gpt4 book ai didi

php - TwitterOAuth : Uncaught exception 'This feature is temporarily unavailable'

转载 作者:可可西里 更新时间:2023-10-31 23:18:46 26 4
gpt4 key购买 nike

我正在 Wordpress 中开发一个应用程序,它允许用户使用他们的 Twitter 帐户登录,然后将用户重定向到一个表单。在提交该表单时,一条推文将发送到用户的 Twitter 句柄。我正在使用 Abraham 的 twitteroauth 来实现 Twitter OAuth。

推特登录成功后的重定向模板源码:

<pre>
<?php
/*
*Template Name: Callback
*/

?>
<?php

session_start();
require "twitteroauth/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;

define('CONSUMER_KEY', "XXXXXXXXXXXXXXX");
define('CONSUMER_SECRET', "XXXXXXXXXXXXXX");
define('OAUTH_CALLBACK', " http://localhost/wordpress/index.php/callback/");

$request_token = [];
$request_token['oauth_token'] = $_SESSION['oauth_token'];
$request_token['oauth_token_secret'] = $_SESSION['oauth_token_secret'];

if (isset($_REQUEST['oauth_token']) && $request_token['oauth_token'] !== $_REQUEST['oauth_token'])
{
echo "Opps! Something went wrong!";
}

else
{
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $request_token['oauth_token'], $request_token['oauth_token_secret']);
$access_token = $connection->oauth("oauth/access_token", array("oauth_verifier" => $_REQUEST['oauth_verifier']));

//print_r($access_token);

$_SESSION['access_token'] = $access_token;
}

$access_token = $_SESSION['access_token'];

$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);

//$user = $connection->get("account/verify_credentials");

//$response = $connection->post("statuses/update", array('status' => 'fsociety'))





//$response = $tmhOAuth->request('POST', $tmhOAuth->url('1.1/statuses/update'), array(
//'status' => 'Conceit to fall on parasol.'


?>


<script>

var count = 0

function addNewMessage(count)
{
if(count > 5)
{
window.alert("NO MORE THAN 5!");
}
else
{
var celeb = document.createElement("input");
celeb.type = "text";
celeb.name = "tweet" + count;
celeb.placeholder = "Tweet" + " " + count;
celebrity.appendChild(celeb);

var date = document.createElement("input");
date.type = "datetime-local";
date.name = "date" + count;
date.placeholder = "message-date" + " " + count;
celebrity.appendChild(date);

celebrity.appendChild(document.createElement("br"));
celebrity.appendChild(document.createElement("br"));
}
}

</script>

<form method = "POST" action = "">

<fieldset>
<a style = "color:red" onclick = "addNewMessage(++count)">Schedule a tweet</a>
<div id = "celebrity"/>
</fieldset>

<br>
<fieldset>
<input type="hidden" name="submitted" id="submitted" value="true" />
<?php wp_nonce_field( 'post_nonce', 'post_nonce_field' ); ?>
<button type="submit"><?php _e('Add Campaign', 'framework') ?></button>
</fieldset>


</form>


<?php



if ( isset( $_POST['submitted'] ))
{
$response = $connection->post("statuses/update", array('status' => 'fsociety'));
}

?>

</pre>

在提交表单时,我使用 Abraham 的 twitteroauth 在用户的 Twitter 时间轴上发布推文,我已尝试按如下方式实现:

<?php



if ( isset( $_POST['submitted'] ))
{
$response = $connection->post("statuses/update", array('status' => 'fsociety'));
}

?>

但是,这是我遇到的错误:

Fatal error:  Uncaught exception 'Abraham\TwitterOAuth\TwitterOAuthException' with message 'This feature is temporarily unavailable' in /opt/lampp/htdocs/wordpress/wp-content/themes/twentyfifteen/tuto/twitteroauth/src/TwitterOAuth.php:137
Stack trace:
#0 /opt/lampp/htdocs/wordpress/wp-content/themes/twentyfifteen/tuto/callback.php(30): Abraham\TwitterOAuth\TwitterOAuth->oauth('oauth/access_to...', Array)
#1 /opt/lampp/htdocs/wordpress/wp-includes/template-loader.php(74): include('/opt/lampp/htdo...')
#2 /opt/lampp/htdocs/wordpress/wp-blog-header.php(16): require_once('/opt/lampp/htdo...')
#3 /opt/lampp/htdocs/wordpress/index.php(17): require('/opt/lampp/htdo...')
#4 {main}
thrown in /opt/lampp/htdocs/wordpress/wp-content/themes/twentyfifteen/tuto/twitteroauth/src/TwitterOAuth.php on line 137

我尝试通过打印 $access_token 进行调试,我确实按预期从 OAuth 提供程序获得了一个唯一 token 。

我的代码似乎有什么问题,我该如何避免引发该异常?

最佳答案

我在学习 API 并通过 Postman 进行调用时遇到了这个问题。看来您只能使用特定的请求 token 对 access_token 端点进行一次调用。如果此调用失败(或确实成功),所有后续调用都会给您“此功能暂时不可用”错误。

您将需要通过 request_token 重新生成访问 token ,并在第一次调用后授权/验证端点。

关于php - TwitterOAuth : Uncaught exception 'This feature is temporarily unavailable' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32095556/

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