使用Python傳送簡訊更新到手機
在本教程中,我們將學習如何在Python中傳送簡訊。我們將使用Twilio傳送簡訊。
首先,訪問Twilio並建立一個帳戶。您將獲得免費試用帳戶。並完成設定。
我們必須安裝一個名為twilio的模組才能使用Twilio客戶端。使用以下命令安裝它。
pip install twilio
現在,訪問Twilio文件,瞭解如何使用Twilio客戶端傳送簡訊。或者按照步驟傳送簡訊。
- 從twilio.rest匯入twilio Client。
- 從您的Twilio帳戶獲取並存儲account_sid和auth_token。
- 透過傳遞account_sid和auth_token來建立Client的例項。
- 現在,從您的Twilio帳戶獲取from號碼。
- 現在,使用client.messages.create(body=message, from_=from_number, to=verified_number)傳送訊息。
- 您將收到訊息。
示例
# importing the client from the twilio from twilio.rest import Client # Your Account Sid and Auth Token from twilio account account_sid = [ACCOUNT_SID] auth_token = [AUTH_TOKEN] # instantiating the Client client = Client(account_sid, auth_token) # sending message message = client.messages.create(body='Hi there! How are you?', from_=[FROM_NUM , to=[VERIFIED_NUMBER]) # printing the sid after success print(message.sid)
如果訊息成功傳送,您將獲得如下所示的雜湊程式碼,沒有任何
SMd954e170ca2545248075c3bc2623aabd
結論
如果您對本教程有任何疑問,請在評論區提出。
廣告