Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to follow/unfollow some friends who authorize my Twitter app.

For example:

User signs in with my twitter application and he wants to follow some people

How does it work? I wrote some code here but not working, The session works fine, The user signs in but create/friendship not working, why?

<?php
session_start();
require_once('TwitterAPIExchange.php');
require_once('tmhOAuth.php');
require_once('tmhUtilities.php');
require_once('twitteroauth.php');
require 'twconfig.php';
echo $_SESSION['oauth_token'];
echo "<br />";
echo $_SESSION['oauth_token_secret'];

$twitteroauth = new TwitterOAuth($consumerKey, $consumerKeySecret, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret'] );
$twitteroauth->post('friendships/create', array('screen_name' => 'savanpaun'));
?>

Simply put, I want people follow/unfollow friends using signup in my application directly.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
163 views
Welcome To Ask or Share your Answers For Others

1 Answer

here is a sample code to follow someone.I’ve had used Abraham library you can get it from here https://github.com/abraham/twitteroauth.

also this is a twitter documentation you can check it out https://dev.twitter.com/rest/reference/post/friendships/create. and to unfollow someone just use 'friendships/destroy'

<?php
echo "<pre>";
$consumerKey = 'your consumer key';
$consumerSecret = 'your consumer secret key';
$oAuthToken = 'your oauth token';
$oAuthSecret = 'your oauth secret';

require_once('twitteroauth.php');

$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $oAuthToken, $oAuthSecret);

//get friend list
$list= $tweet->post('friendships/create', array('screen_name' => 'archish9'));

var_dump(json_decode($list));
print_r($list);
?>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...