如何在twitter api中的关注按钮回调函数中检索用户详细信息?

时间:2015-10-22 05:44:23

标签: javascript jquery twitter twitter-oauth

我试图在跟随按钮回调函数中检索登录的用户名和位置详细信息。

twttr.ready(function (twttr) {
   twttr.events.bind('follow', function (event) {
      $.ajax({
            type: "GET",
            dataType: "json",
            url: "https://api.twitter.com/1.1/users/show.json?user_id=" + event.data.user_id,
            success: function (data) {
               console.log(data);
            }
       });                  
    });
 });

但我无法检索用户详细信息。是否可以检索用户详细信息?

1 个答案:

答案 0 :(得分:1)

看起来show已包含用户详细信息https://dev.twitter.com/rest/reference/get/users/show

示例结果:

{
  "contributors_enabled": false,
  "created_at": "Sat Dec 14 04:35:55 +0000 2013",
  "default_profile": false,
  "default_profile_image": false,
  "description": "Developer and Platform Relations @Twitter. We are developer advocates. We can't answer all your questions, but we listen to all of them!",
  "entities": {
    "description": {
      "urls": []
    },
    "url": {
      "urls": [
        {
          "display_url": "dev.twitter.com",
          "expanded_url": "https://dev.twitter.com/",
          "indices": [
            0,
            23
          ],
          "url": "https://t.co/66w26cua1O"
        }
      ]
    }
  },
  "favourites_count": 757,
  "follow_request_sent": false,
  "followers_count": 143916,
  "following": false,
  "friends_count": 1484,
  "geo_enabled": true,
  "id": 2244994945,
  "id_str": "2244994945",
  "is_translation_enabled": false,
  "is_translator": false,
  "lang": "en",
  "listed_count": 516,
  "location": "Internet",
  "name": "TwitterDev",
  "notifications": false,
  "profile_background_color": "FFFFFF",
  "profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png",