可以使用Python从我的号码发送消息到另一个号码。

huangapple go评论62阅读模式
英文:

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)

huangapple
  • 本文由 发表于 2023年5月29日 15:37:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76355467.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定