gpt4 book ai didi

php - 推特 REST API "Could not authenticate you."

转载 作者:搜寻专家 更新时间:2023-10-31 21:27:03 29 4
gpt4 key购买 nike

我到处寻求帮助以找到解决方案,但就是找不到。我知道我已正确输入 token 和 key 并为我的应用正确设置权限。我完全卡住了

<?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 />";
}
?>

最佳答案

  1. 您不能在 URL 中有查询字符串的同时调用 setGetfield。将查询参数全部移动到 setGetfield

  2. 遍历 $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 />";
}

关于php - 推特 REST API "Could not authenticate you.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34476379/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com