【问题标题】:How to get your website visitors to follow twitter accounts from your website如何让您的网站访问者关注您网站上的 Twitter 帐户
【发布时间】:2014-12-13 00:23:05
【问题描述】:

我是这个论坛的新手,如果我的问题不恰当或不够清楚,请接受我的歉意。

我有一个网站,其中列出了 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 是 twitter api 请求的 php 包装器,我也应该分享它吗?如果有人可以提供帮助,请提前致谢。

【问题讨论】:

  • 我认为您必须先让用户登录您的 Twitter 应用程序,然后才能以他们的名义执行操作……
  • 我正在为我的访问者使用 twitter 登录选项,他们将在通过 twitter 登录后关注用户屏幕!!
  • 我也面临同样的问题,谁能帮忙。

标签: javascript php ajax twitter


【解决方案1】:

不要从服务器端这样做。没有必要也不合适。

为此使用Twitter web intents。它们允许您网站的用户使用他们登录的 Twitter 帐户执行各种操作,包括发布状态、转发状态以及关注其他 Twitter 用户。

【讨论】:

  • 首先,我非常感谢您的关心并回答我的问题 :)duskwuff 实际上,如果您看到我的上述代码,我将 api.twitter.com/1.1/friendships/create.json api 用于以下目的,因为在我的项目 Twitter当用户单击关注按钮时不应打开弹出屏幕,并且在此 snerio 创建 api 是强制性的,因为它有助于在不打开弹出窗口的情况下关注用户!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-13
  • 2011-09-08
  • 1970-01-01
  • 2010-12-01
  • 2010-10-13
  • 1970-01-01
相关资源
最近更新 更多