我是这个论坛的新手,所以如果我的问题不合适或不够清楚,请接受我的歉意。
我有一个网站,其中列出了Twitter用户,每个用户都有关注按钮,但是当访问者单击"关注"按钮时,该用户将从我的Twitter帐户(具有用于身份验证的应用程序)而不是访问者帐户中关注。 所以基本上我希望这些帐户被访问者关注 Twitter 帐户而不是我的。
当用户单击"关注"按钮时,将进行 AJAX 调用以将用户名发送到运行以下代码以使该用户关注的页面。
<?php
ini_set('display_errors', 1);
require_once('lib/TwitterAPIExchange.php');
$uname=$_REQUEST['name'];
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
'oauth_access_token' => "XXXXXX-XXXXXXXXXX",
'oauth_access_token_secret' => "XXXXXXXXXX",
'consumer_key' => "XXXXXXXXXX",
'consumer_secret' => "XXXXXXXXXX"
);
// Choose the url you want from the docs, this is the users/show
$url = 'https://api.twitter.com/1.1/friendships/create.json';
// The request method, according to the docs, is GET, not POST
$requestMethod = 'POST';
$varl=$uname;
// Set up your get string, we're using my screen name here
//$getfield = '?screen_name='.$varl;
$postfields = array(
'screen_name' => $varl
);
// Create the object
$twitter = new TwitterAPIExchange($settings);
$twitter->buildOauth($url, $requestMethod)
->setPostfields($postfields)
->performRequest();
TwitterAPIExchange.php php wrapper for Twitter api request 我是否也应该分享?如果有人可以提供帮助,请提前感谢。
不要从服务器端执行此操作。这是没有必要或不合适的。
为此,请使用 Twitter 网络意图。它们允许你网站的用户使用他们登录的 Twitter 帐户执行各种操作,包括发布状态、转发状态和关注其他 Twitter 用户。