简体   繁体   中英

How to follow users who sign in with twitter on my website?

require("twitteroauth/twitteroauth.php");  
session_start();
//Site Account
$siteauth = new TwitterOAuth('{Consumer key}', '{Consumer secret}', '{Access token}', '{Access token secret}');
$access_token = $siteauth->getAccessToken($_GET['oauth_verifier']);
$_SESSION['access_token'] = $access_token;
$site_info = $siteauth->get('account/verify_credentials');

var_dump($site_info);

I'm trying to create a $twitteroauth object in order to use the next code:

$follows_faelazo = $siteauth->get('friendships/exists', 'MY-VISTOTR-ACCOUNT', 'user_b' => 'MY-SITE_ACCOUNT'));
if(!$follows_faelazo){
    echo 'You are NOT following @faelazo!';
    $siteauth->post('friendships/create', array('screen_name' => 'MY-VISTOR'));
}

What I'm trying to do is to follow users who log in to my site using twitter, any idea what's wrong? I'm kind of new with the twitter API.

please go to twitter dev - > My app - > Your App -> settings -> Application type set to Read, Write and Access direct messages.

First you are checking if you have already followed the person. to do this 2 parameters are required ,.

 // uname
 1.) USER_FOLLOWING
 2.) USER_FOLLOWED

Now the 2nd call will be to follow method so you could follow, for this 1 param is req.

//this can be uid/uname
1.) USER_T0_BE_FOLLOWED

For above mentioned please make sure you are calling methods with appropriate param.

eg) in the first you need to pass 4 param, client_id, client_secret , outhid, outhsecret

initially before this user needs to authenticate the app.

everything else lloks fine hope you passing proper param thats just one concern.

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