英文:
can send message from my number to another number using python
问题
我想使用Twilio或任何其他Python短信API发送短信,但我希望在发送消息时显示我的个人号码。
我尝试使用Twilio,但在通过Twilio发送时,它显示了一个发送者ID而不是发送者号码。
英文:
I want to send an sms using twilio or any other sms api with python but I want my personal number to show when i send a message
i tried using twilio but it didnt work while sending through twilio it shows a sender id not the sender number.
答案1
得分: 1
这是在Python中发送消息的方法:
import os
from twilio.rest import Client
account_sid = os.environ['TWILIO_ACCOUNT_SID']
auth_token = os.environ['TWILIO_AUTH_TOKEN']
client = Client(account_sid, auth_token)
message = client.messages.create(
body='你好',
from_='+15017122661',
to='+15558675310'
)
原因是它显示了“Sender ID”(我假设你指的是消息SID),是因为你可能正在打印消息SID:
print(message.sid)
你可以打印消息的发送者号码,而不是打印message.sid
:
print(message.from)
如果你想显示你的个人号码(假设你将消息发送到你的号码):
print(message.to)
英文:
This is how you send a message in Python:
import os
from twilio.rest import Client
account_sid = os.environ['TWILIO_ACCOUNT_SID']
auth_token = os.environ['TWILIO_AUTH_TOKEN']
client = Client(account_sid, auth_token)
message = client.messages.create(
body='Hi there',
from_='+15017122661',
to='+15558675310'
)
The reason it's showing the "Sender ID" (which I'm assuming you mean the message SID) is because you may be printing the message SID:
print(message.sid)
Instead of printing the message.sid
, you can print the message's from number (sender's number):
print(message.from)
If you want to show your personal number (assuming you're sending the message to your number):
print(message.to)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论