使用来自 Twilio 的 SID 结果更新 Google 表格

问题描述 投票:0回答:0

我正在创建一个 Google 表格,其中包含姓名和号码以向人们发送短信。我正在使用 python(我是业余爱好者)、gspread、twilio,我想用每个电话号码生成的 SID 号码更新电子表格。这是我到目前为止创建的代码。

import gspread
import json
from google.oauth2.credentials import Credentials
import datetime
from twilio.rest import Client
#create client
account = "xxxx"
token  = "xxxx"
client = Client(account, token)

# connect google spreadsheet and return worksheet info
gc=gspread.service_account()
sh = gc.open("Twilio")
wk = sh.worksheet("SMS")
worksheet = sh.worksheet("SMS")
scope = ['https://spreadsheets.google.com/feeds','https://www.googleapis.com/auth/drive']
print(type(worksheet))
# get cell value from worksheet(ws)

# Loop through the names and numbers and send a text message to each phone number 
names = wk.batch_get(('a2:a',))[0]
numbers = wk.batch_get(('c2:c',))[0]

for i in range(len(names)):

# send a message to a recipient_number
# add recipient name to the message
    message = client.messages.create(
        from_="+18447011479",
        to = numbers[i],
        body=f"Hello {names[i][0]}, this is a test message from Twilio.",
    media_url="https://raw.githubusercontent.com/dianephan/flask_upload_photos/main/UPLOADS/DRAW_THE_OWL_MEME.png",)

# Update sheet Column D with SID results
#worksheet.update stuck here

python twilio gspread
© www.soinside.com 2019 - 2024. All rights reserved.