-1

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.

ErstwhileIII
  • 4,829
  • 2
  • 23
  • 37
Savan Paun
  • 1,723
  • 2
  • 16
  • 24

2 Answers2

0

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);
?>
archish
  • 142
  • 1
  • 13
  • check this out to unfollow someone https://dev.twitter.com/rest/reference/post/friendships/destroy you can also use twitter console tool for testing purpose https://dev.twitter.com/rest/tools/console – archish Jan 05 '15 at 11:51
  • it's not fully answer what i want .. any user can unfollow his following without twitter sign in ... – Savan Paun Jan 10 '15 at 07:01
  • 3
    twitter use OAuth. see this https://dev.twitter.com/oauth. user have to give permission to twitter app. without user's permission you can't access there information. you can save there oAuthToken and oAuthSecret in your db and use them later, if you save them you don't have to ask them to login every time, but to get there oAuthToken and oAuthSecret user have to login one time. without login it is not possible to assess anything. – archish Jan 10 '15 at 12:27
  • good answer yes user will signin every time but i want only that after signin with my app he can unfollow or follow his own friends – Savan Paun Jan 13 '15 at 04:09
  • @SavanPaun you just want to follow or unfollow friends , so suppose i am using your app so what will be the steps i should do to follow and unfollow someone. how your app will work just tell me overview so that i can help you. – archish Jan 17 '15 at 07:10
0

I copy paste you example and replace in the last line with destroy command

<?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/destroy', array('user_id' => 'iduser'));
?>

this line

$twitteroauth->post('friendships/destroy', array('user_id' => 'iduser'));

I hope that this help you in some way

best

Emiliano
  • 698
  • 9
  • 30
  • 1
    not working read the question first i want a unfollow button code for example user a signup my app and he want to unfollow his follower – Savan Paun Jan 10 '15 at 06:58