【问题标题】:How to update profile image to twitter using REST api?如何使用 REST api 将个人资料图片更新到 Twitter?
【发布时间】:2015-03-04 06:27:52
【问题描述】:

有人有工作代码或示例来更新 Twitter 个人资料图片吗?

python-oauth2 好不好。?我应该为此使用其他库吗?

使用:python 2.7,Django 1.7 python-oauth2

image_post = "https://api.twitter.com/1.1/statuses/update.json?status=ThisOneWorksPerfectly"
resp, content = client.request(image_post, "POST")

上面的代码工作得很好,但我把代码改成了updateprofileimage(见下文...)

来自update_profile_image

image_post = "https://api.twitter.com/1.1/account/update_profile_image.json?image={}".format(encodedImage)
resp, content = client.request(image_post, "POST")

错误:

'{"errors":[{"message":"Could not authenticate you","code":32}]}'

【问题讨论】:

    标签: python django twitter oauth-2.0


    【解决方案1】:

    您应该将图像作为 POST 参数传递,而不是作为查询参数传递。您可以通过向 client.request 方法提供第三个参数 (body) 来实现,如下所示:

    image_post = "https://api.twitter.com/1.1/account/update_profile_image.json"
    resp, content = client.request(image_post, "POST", "image=" + base64EncodedImage)
    

    【讨论】:

    • 抱歉,混淆了 Python 和 PHP... 现已修复 ("+")
    • 确保使用正确的 image_post URL(现在已编辑)并粘贴完整的错误(如果仍然存在)
    • 如果我发送虚假数据而不是有效的 base64 编码图片,我可以使用自己的配置文件/curl 命令重现此“无法识别”错误。
    • 在那之后使用 python-twitter 我解决了我的问题。
    猜你喜欢
    • 1970-01-01
    • 2015-04-14
    • 1970-01-01
    • 2011-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-15
    相关资源
    最近更新 更多