简体   繁体   English

PHP API中的Twitter API v 1.1代码

[英]Twitter API v 1.1 code in PHP

I am using twitter API v1.1 to get tweets in my web application the code for getting tweets is as $name = 'zkalvi'; $url = "https://api.twitter.com/1.1/search/tweets.json/".$name; $tweets = json_decode(file_get_contents($url)); echo '<ul>'; foreach($tweets as $tweet) { echo '<li>'.$tweet->text.'</li>';
} echo '</ul>';
我正在使用twitter API v1.1在我的网络应用程序中获取推文获取推文的代码是$name = 'zkalvi'; $url = "https://api.twitter.com/1.1/search/tweets.json/".$name; $tweets = json_decode(file_get_contents($url)); echo '<ul>'; foreach($tweets as $tweet) { echo '<li>'.$tweet->text.'</li>';
} echo '</ul>';
$name = 'zkalvi'; $url = "https://api.twitter.com/1.1/search/tweets.json/".$name; $tweets = json_decode(file_get_contents($url)); echo '<ul>'; foreach($tweets as $tweet) { echo '<li>'.$tweet->text.'</li>';
} echo '</ul>';
and $name = 'zkalvi'; $url = "https://api.twitter.com/1.1/search/tweets.json/".$name; $tweets = simplexml_load_file($url); echo '<ul>'; foreach($tweets as $tweet) { echo '<li>'.$tweet->text.'</li>'; } echo '</ul>'; $name = 'zkalvi'; $url = "https://api.twitter.com/1.1/search/tweets.json/".$name; $tweets = simplexml_load_file($url); echo '<ul>'; foreach($tweets as $tweet) { echo '<li>'.$tweet->text.'</li>'; } echo '</ul>'; $name = 'zkalvi'; $url = "https://api.twitter.com/1.1/search/tweets.json/".$name; $tweets = simplexml_load_file($url); echo '<ul>'; foreach($tweets as $tweet) { echo '<li>'.$tweet->text.'</li>'; } echo '</ul>'; both of these codes are not showing the tweets. 这两个代码都没有显示推文。 Please help me why the tweets are not showing and how could I show the tweets? 请帮助我为什么推文没有显示,我怎么能显示推文? Thanks in advance. 提前致谢。

first of all, the way you are calling is wrong, your url should be like this https://api.twitter.com/1.1/search/tweets.json?q=zkalvi . 首先,你打电话的方式是错误的,你的网址应该是这样的https://api.twitter.com/1.1/search/tweets.json?q=zkalvi

By this url you will get following output 通过此URL,您将获得以下输出

{"errors":[{"message":"Bad Authentication data","code":215}]}

This is because , in twitter 1.1 version, most of thing needs authentication. 这是因为,在twitter 1.1版本中,大多数东西都需要身份验证。 So better you use twitter server side library for getting results. 因此,最好使用twitter服务器端库来获取结果。

Here is link for twitteroauth library for php twitteroauth 这里是用于php twitteroauth的 twitteroauth库的链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM