如何使用Twitter API从id_str获取用户信息(如屏幕名称、描述等)


How to get user information (like screen_name, description, etc) from id_str using Twitter API?

假设我有以下文本"转发tomgabihttps://..."在quoted_status中,使用收集https://api.twitter.com/1.1/statuses/user_timeline.json.当我在浏览器中打开这个链接时,我可以看到很多关于用户的信息(推特、屏幕名称、描述等)。URL更改为https://twitter.com/wiltonpfilho/status/715320170655440896.我如何使用Twitter API从这个新的URL获取用户信息(tweet、screen_name、description等)。我可以从id_str(在URL中)访问用户信息吗?

检查此链接

所以你真的不想再做这个客户端了。(刚刚浏览了大量文档,开发人员建议在服务器端执行所有oAuth)

你需要做什么:

第一个:注册https://dev.twitter.com,并制作新的应用程序。

第二:注意:您的消费者密钥/机密以及访问令牌/机密

第三:下载Twitter oAuth库(在本例中,我使用了PHP库https://github.com/abraham/twitteroauth,位于此处的附加库:https://dev.twitter.com/docs/twitter-libraries)

第四个:(如果使用php)确保cURL已启用,如果您在LAMP上运行,这里有您需要的命令:

sudo apt-get install php5-curl

第五:制作一个新的PHP文件并插入以下内容:感谢Tom Elliothttp://www.webdevdoor.com/php/authenticating-twitter-feed-timeline-oauth/

<?php
session_start();
require_once("twitteroauth/twitteroauth/twitteroauth.php"); //Path to twitteroauth library you downloaded in step 3
$twitteruser = "twitterusername"; //user name you want to reference
$notweets = 30; //how many tweets you want to retrieve
$consumerkey = "12345"; //Noted keys from step 2
$consumersecret = "123456789"; //Noted keys from step 2
$accesstoken = "123456789"; //Noted keys from step 2
$accesstokensecret = "12345"; //Noted keys from step 2
function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret) {
  $connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret);
  return $connection;
}
$connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);
$tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$twitteruser."&count=".$notweets);
echo json_encode($tweets);
echo $tweets; //testing remove for production   
?>

然后砰的一声,你完了我知道这不是一个纯粹的js解决方案,但再次阅读新的Twitter API 1.1文档,他们真的不希望你做这个客户端网站。希望这能有所帮助!

使用状态/查找。

例如,https://api.twitter.com/1.1/statuses/lookup.json?id=715320170655440896