如果需要进行身份验证,如何才能使此AJAX调用正常工作?

时间:2022-08-25 18:09:03

I would like to know how I can make AJAX calls to the Twitter API in order to get pictures of twitter users and display them back to the browser . The thing is that when I use the PHP method , it takes a VERY VERY LONG time to display profile pictures of a 100 twitter users generated by a loop .. So through this URL below that returns information about a twitter user, how could I use it with Jquery AJAX in order to fetch profile pictures images ? This requires the call to be authenticated ..

我想知道如何对Twitter API进行AJAX调用,以便获取Twitter用户的照片并将其显示回浏览器。问题是当我使用PHP方法时,显示由循环生成的100个Twitter用户的个人资料图片需要非常长的时间。因此,通过下面的URL返回有关Twitter用户的信息,我该如何使用它与Jquery AJAX,以获取个人资料图片图像?这需要对呼叫进行身份验证。

https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=twitterapi&count=2

Below is the PHP method I used , but it's SOO SLOW ..

下面是我使用的PHP方法,但它是SOO SLOW ..

 $id = $_GET['screen_name']; 
    * Create a TwitterOauth object with consumer/user tokens. */
    $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
    foreach($id as $key  => $value) {
      $url = $connection->get('users/show', array('screen_name' => $value));
      $results  = json_encode($url);
      $data = json_decode($results, true);
      $image = '';  
      if(is_array($data)){  
       $image = $data['profile_image_url'];  ;
       $image_bigger = str_replace('_normal', '_bigger',$image); 
     }

    }
    ?>

1 个解决方案

#1


0  

Try the users/lookup endpoint which will let you pull 100 profiles at a time. https://dev.twitter.com/docs/api/1.1/get/users/lookup

尝试用户/查找端点,一次可以提取100个配置文件。 https://dev.twitter.com/docs/api/1.1/get/users/lookup

Note also that you cannot make pure ajax calls directly to the new Twitter API without exposing your secret keys to the public. You'll have to proxy these calls via your own back end.

另请注意,您不能直接向新的Twitter API发出纯粹的ajax调用,而不会将您的密钥暴露给公众。您必须通过自己的后端代理这些电话。

#1


0  

Try the users/lookup endpoint which will let you pull 100 profiles at a time. https://dev.twitter.com/docs/api/1.1/get/users/lookup

尝试用户/查找端点,一次可以提取100个配置文件。 https://dev.twitter.com/docs/api/1.1/get/users/lookup

Note also that you cannot make pure ajax calls directly to the new Twitter API without exposing your secret keys to the public. You'll have to proxy these calls via your own back end.

另请注意,您不能直接向新的Twitter API发出纯粹的ajax调用,而不会将您的密钥暴露给公众。您必须通过自己的后端代理这些电话。