【发布时间】:2011-07-23 02:57:10
【问题描述】:
我试图弄清楚如何让我的用户通过点击我网站上的链接来发布推文。这是我设计的流程:
- 我网站上某处的链接将提供优惠:“发送推特并获得优惠券”。
- 一旦他们点击了优惠链接,他们就会被重定向到 Twitter 以获得授权。
- 在他们授予连接其 Twitter 个人资料的权限后,我想使用 Twitter API 发送一个帖子,其中包含预先填充的消息,例如:“免费试用此在线工具:http”//mylink .com”。消息发布后,需要将它们重定向回我的网站,并转到带有优惠券代码的页面。
到目前为止,我完成了大约 75%。
- 我安装了twitterOauth library
- 基于演示示例,我现在可以执行以下操作: -- 链接到 Twitter (DEMO) -- 使用 Twitter 登录用户 -- 重定向回我的网站
我仍然需要弄清楚如何发布推文...理想情况下,我想显示将要发布的消息,但没有编辑功能,只是为了让他们知道。我可能会在第一页上显示它,这意味着一旦他们授予 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
?>
【问题讨论】: