Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
174 views
in Technique[技术] by (71.8m points)

php - How to unfollow some friend who sign up my app twitter

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

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

1 Reply

0 votes
by (71.8m points)

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);
?>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...