Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php TwitterRESTAPI“;无法验证您的身份。”;_Php_Twitter Oauth - Fatal编程技术网

Php TwitterRESTAPI“;无法验证您的身份。”;

Php TwitterRESTAPI“;无法验证您的身份。”;,php,twitter-oauth,Php,Twitter Oauth,我到处找人帮忙找解决办法,但就是找不到。我知道我已经正确输入了令牌和密钥,并为我的应用程序正确设置了权限。我完全卡住了 <?php require_once("TwitterAPIExchange.php"); $settings = array( "oauth_access_token" => "2417489002-zSklTBdkf0qidQQZq3TiEa2IlAxh6lu5aCG988G", "oauth_access_token_secret" =>

我到处找人帮忙找解决办法,但就是找不到。我知道我已经正确输入了令牌和密钥,并为我的应用程序正确设置了权限。我完全卡住了

<?php
require_once("TwitterAPIExchange.php");

$settings = array(
    "oauth_access_token" => "2417489002-zSklTBdkf0qidQQZq3TiEa2IlAxh6lu5aCG988G",
    "oauth_access_token_secret" => "VTY7I731dDJfcs3myeKp14TIewUI73tDB62Z8Cncbl46o",
    "consumer_key" => "bYKS1A8gKcVF7LFy0ZaSWR8J6",
    "consumer_secret" => "  UCakq879nUFQe6HCHCiXRj4ZThFOFsADvAx95oD5xglpXau1Ra"
);

$url = "https://api.twitter.com/1.1/search/tweets.json?q=propane";
$requestMethod = "GET";
$getfield = "?screen_name=iagdotme&count=20";
$twitter = new TwitterAPIExchange($settings);
$string = json_decode($twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest(), $assoc = TRUE);
if($string["errors"][0]["message"] != "") {
    echo "<h3>Sorry, there was a problem.</h3><p>Twitter returned the following error messsage:
    </p><p><em>".$string[errors][0]["message"]."</em></p>";
    exit();
}
foreach($string as $items) {
    echo "Time and Date of Tweet: ".$items['created_at']."<br/>";
    echo "Tweet: ".$items["user"]["name"]."<br/>";
    echo "Tweeted by: ".$items["user"]["name"]."<br/>";
    echo "Screen name: ".$items["user"]["screen_name"]."<br/>";
    echo "Followers: ".$items["user"]["followers_count"]."<br/>";
    echo "Friends: ".$items["user"]["friends_count"]."<br />";
    echo "Listed: ".$items["user"]["listed_count"]."<br /><hr />";
}
?>

  • URL中不能有查询字符串,也不能调用
    setGetfield
    。将查询参数全部移入
    setGetfield

  • 迭代
    $string[“statuses”]
    而不是
    $string

  • 经过这些修改后,生成的代码是:

    $url = "https://api.twitter.com/1.1/search/tweets.json";
    $requestMethod = "GET";
    $getfield = "?q=propane&screen_name=iagdotme&count=20";
    $twitter = new TwitterAPIExchange($settings);
    $string = json_decode($twitter->setGetfield($getfield)
    ->buildOauth($url, $requestMethod)
    ->performRequest(), $assoc = TRUE);
    if($string["errors"][0]["message"] != "") {
        echo "<h3>Sorry, there was a problem.</h3><p>Twitter returned the following error messsage:
        </p><p><em>".$string[errors][0]["message"]."</em></p>";
        exit();
    }
    foreach($string["statuses"] as $items) {
        echo "Time and Date of Tweet: ".$items['created_at']."<br/>";
        echo "Tweet: ".$items["user"]["name"]."<br/>";
        echo "Tweeted by: ".$items["user"]["name"]."<br/>";
        echo "Screen name: ".$items["user"]["screen_name"]."<br/>";
        echo "Followers: ".$items["user"]["followers_count"]."<br/>";
        echo "Friends: ".$items["user"]["friends_count"]."<br />";
        echo "Listed: ".$items["user"]["listed_count"]."<br /><hr />";
    }
    
    $url=”https://api.twitter.com/1.1/search/tweets.json";
    $requestMethod=“GET”;
    $getfield=“?q=丙烷和屏幕名称=iagdotme和计数=20”;
    $twitter=newtwitterapiexchange($settings);
    $string=json\u解码($twitter->setGetfield($getfield)
    ->buildOauth($url,$requestMethod)
    ->performRequest(),$assoc=TRUE);
    如果($string[“errors”][0][“message”]!=“”){
    echo“抱歉,出现问题。Twitter返回以下错误消息:
    “$string[错误][0][“消息”]。”

    “; 退出(); } foreach($string[“status”]作为$items){ echo“Tweet的时间和日期:.$items['created_at']。”
    ; echo“Tweet:.$items[“user”][“name”]。“
    ”; echo“推特者:“.$items[“user”][“name”]。
    ”; echo“屏幕名称:”.$items[“用户”][“屏幕名称”]。“
    ”; 回显“追随者:”.$items[“用户”][“追随者计数”]。“
    ”; 回显“好友:”.$items[“用户”][“好友计数”]。“
    ”; echo“列出:”.$items[“用户”][“列出的计数”]。“

    ”; }
    错误提示您和您的代码缺少访问该屏幕名称的用户名和密码身份验证