【问题标题】:Pull twitter profile image拉推特头像
【发布时间】:2011-01-08 01:48:56
【问题描述】:

有没有一种用 PHP 或 Javascript 快速提取 Twitter 个人资料图像的方法?我需要获取完整图像的网址(不是头像大小)。谢谢。任何代码示例都很好。

【问题讨论】:

    标签: php javascript html api twitter


    【解决方案1】:

    Twitter 一个不错的简单网址。

    https://api.twitter.com/1/users/profile_image/abraham

    它有像“?size=bigger”这样的尺寸选项

    您可以在Little known Twitter and TwitterAPI tips and tricks 上阅读更多相关信息。

    Twitter 现在的文档为 GET users/profile_image/:screen_name

    更新:已从 API 的 v1.1 中删除了对此方法的支持。 Recommended practice 未来是 GET /users/show 并在您的服务/应用中本地缓存 profile_image_url

    【讨论】:

    【解决方案2】:
    function get_big_profile_image($username, $size = '') {
      $api_call = 'http://twitter.com/users/show/'.$username.'.json';
      $results = json_decode(file_get_contents($api_call));
      return str_replace('_normal', $size, $results->profile_image_url);
    }
    

    get_big_profile_image('bobsaget', '_bigger') 应该返回一个大头像: http://a1.twimg.com/profile_images/330305510/n229938150541_9850_bigger.jpg

    get_big_profile_image('bobsaget') 应该返回一个更大的图像:http://a1.twimg.com/profile_images/330305510/n229938150541_9850.jpg

    【讨论】:

    • 此功能不再起作用。还有什么想法吗?还有其他可用的解决方法吗?
    • 不工作。错误:{"errors":[{"message":"抱歉,该页面不存在","code":34}]}
    【解决方案3】:

    抱歉,如果这是现在已知的事情,但我在搜索期间没有看到任何地方记录它,包括官方 Twitter 文档。

    您可以添加 ?size=original 作为参数,它将为用户返回原始上传的图像。

    所以: http://api.twitter.com/1/users/profile_image/twitter.json?size=original

    【讨论】:

      【解决方案4】:

      以前的回答者提供了我想链接到原始 twitter api 文档页面的正确答案,所以你会知道它实际上是一种官方的做事方式:

      您需要指定?size=

      • 更大 - 73 x 73 像素
      • 正常 - 48 x 48 像素
      • 迷你 - 24 像素 x 24 像素
      http://api.twitter.com/1/users/profile_image/twitter.json?size=bigger
      http://api.twitter.com/1/users/profile_image/twitter.json?size=normal
      

      http://dev.twitter.com/doc/get/users/profile_image/:screen_name

      【讨论】:

        【解决方案5】:

        因此,它不在文档中 (http://dev.twitter.com/doc/get/users/profile_image/:screen_name),但在通过指定三种尺寸中的任何一种(更大, normal, mini), 只需去掉文件扩展名前的后缀即可得到原图。嗯……这可以安全使用吗?

        例如,这个查询:api.twitter.com/1/users/profile_image/rrbrambley

        结果:a2.twimg.com/profile_images/931772958/deformed_cropped_headonly_normal.jpg

        如果我通过删除“_normal”来更改此网址,那么我会得到原始图像:a2.twimg.com/profile_images/931772958/deformed_cropped_headonly.jpg

        我知道有些应用会使用原始图像。一定是这样吗?

        【讨论】:

          【解决方案6】:

          【讨论】:

            【解决方案7】:

            我知道这不是所要求的完整代码示例(因为有多种方法可以做到这一点),但是您是否已经有了头像的 URL?我注意到将“.../eric.png”变成“.../eric_bigger.png”会产生更大的图像。当“_bigger”已经存在时,删除它会给我原始图像的 URL。

            我用几个追随者的个人资料图片对此进行了测试,当个人资料图片> 150px 正方形时,它可以工作。

            【讨论】:

              【解决方案8】:
              猜你喜欢
              • 2016-04-03
              • 1970-01-01
              • 2012-07-18
              • 2015-08-24
              • 2012-04-14
              • 2013-09-25
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多