简体   繁体   中英

How to get your website visitors to follow twitter accounts from your website

I am new on this forum, so accept my apologies if my question is inappropriate or is not clear enough.

I have a website where Twitter users are listed having follow button against each user, but when visitor click on 'follow' button then that user get followed from my Twitter account (which have app that is being used for authentication) instead of visitors account. so basically i want these accounts to be followed by visitors twitter account not mine.

when user clicks on follow button an ajax call is made to send username to page where following code runs to get that user followed.

<?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 is php wrapper for twitter api request should i share that too ? Thanks in advance if anyone can help.

Don't do that from the server side. It's not necessary or appropriate.

Use Twitter web intents for this. They allow users of your site to perform a variety of actions using their logged-in Twitter account, including posting statuses, retweeting statuses, and following other Twitter users.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM