我正在尝试通过关注我网站上的链接来弄清楚如何让我的用户发布推文。这是我设计的过程:
我还需要弄清楚如何发布推文......理想情况下,我想展示将要发布的消息,但没有编辑功能,只是为了让他们知道。我可以在第一页上显示它,这意味着我想在重定向到优惠券代码之前,一旦授予Twitter权限就自动发布。我在哪里添加POST功能?
这是return.php代码。
<?php
/* Start session and load library. */
session_start();
require_once('twitteroauth/twitteroauth.php');
require_once('config.php');
// This is where we end up when the user comes back from twitter.
// First, we creat a new connection object
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
// Then we use it to send a twitter message
$connection->post('statuses/update', array('status' => 'Test message'));
// Finally, we redirect the user to the coupon page
header('Location: /privacy'); // Supplies user with coupon
?>
答案 0 :(得分:3)
当Twitter将用户重定向回您的网站时,请发送推文然后使用优惠券代码加载页面。尽管如果他们授权您的应用,请确保您已通知用户他们的状态将会更新。
您忘记了交换access_tokens:
<?php
/* Start session and load library. */
session_start();
require_once('twitteroauth/twitteroauth.php');
require_once('config.php');
// This is where we end up when the user comes back from twitter.
// First, we creat a new connection object
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
$token_credentials = $connection->getAccessToken($_REQUEST['oauth_verifier']);
$_SESSION['oauth_token'] = $token_credentials['oauth_token']
$_SESSION['oauth_token_secret'] = $token_credentials['oauth_token_secret'];
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
// Then we use it to send a twitter message
$connection->post('statuses/update', array('status' => 'Test message'));
// Finally, we redirect the user to the coupon page
header('Location: /privacy'); // Supplies user with coupon
?>