Saturday, January 21, 2017

How to silently or offline post content to users wall Twitter [Solved]

How to silently post share into  Twitter user wall following below  instruction. its difficult if you might be you are going wrong direction . do not worry for this please follow step by step.

Step1- Dowonload Twitter Auth here

Step2-> Create a project folder in xampp/htdoc/TwSilentPost

1. Then create config.php within project folder

<?php
#####################config.php#######################
define('CONSUMER_KEY', 'XXXXXX');
define('CONSUMER_SECRET', 'XXXXXXXXX');
define('OAUTH_CALLBACK', 'http://localhost/TwSilentPost/process.php');
?>

Step2-> Go to Twitter App login create app and input all required information against app

Callback URL :  http://localhost/TwSilentPost/process.php



Step3->create process.php and paste below code

<?php
#######################process.php###############################
session_start();
include_once("config.php");
include_once("inc/twitteroauth.php");
$hostName = 'http://'.$_SERVER['HTTP_HOST'];

if(isset($_REQUEST['oauth_token']) && $_SESSION['token']  !== $_REQUEST['oauth_token']) {

//If token is old, distroy session and redirect user to index.php
session_destroy();
header('Location: index.php');

}elseif(isset($_REQUEST['oauth_token']) && $_SESSION['token'] == $_REQUEST['oauth_token']) {

//Successful response returns oauth_token, oauth_token_secret, user_id, and screen_name
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['token'] , $_SESSION['token_secret']);
$access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']);


if($connection->http_code == '200')
{

//Redirect user to twitter
$_SESSION['status'] = 'verified';
$_SESSION['request_vars'] = $access_token;


$oauth_token = $_SESSION['request_vars']['oauth_token'];
$oauth_token_secret = $_SESSION['request_vars']['oauth_token_secret'];
###############################store auth token and auth secret key in Database table######
##INSTER TABLE (userid,TwAtuhToken,TwAuthSecreet)values(123,$oauth_token,$oauth_token_secret);
##################################################################

header('Location: success_msg.php');
}else{
die("error, try again later!");
}

}else{

if(isset($_GET["denied"]))
{
header('Location: index.php');
die();
}

//Fresh authentication
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
$request_token = $connection->getRequestToken(OAUTH_CALLBACK);

//Received token info from twitter
$_SESSION['token'] = $request_token['oauth_token'];
$_SESSION['token_secret'] = $request_token['oauth_token_secret'];

//Any value other than 200 is failure, so continue only if http code is 200
if($connection->http_code == '200')
{
//redirect user to twitter
$twitter_url = $connection->getAuthorizeURL($request_token['oauth_token']);
header('Location: ' . $twitter_url);
}else{
die("error connecting to twitter! try again later!");
}
}
?>

Step4->Create index.php

<?php
##################index.php########################
echo '<a href="process.php"><img src="images/sign-in-with-twitter.png" width="151" height="24" border="0" /></a>';
?>


Step5-> create postTw.php file for share content to user wall
<?php
##############################postTw.php########################
include_once("config.php");
include_once("inc/twitteroauth.php");

$statusText="hey, this is test.bikash";
$twitter_oauth_token = get access token from db
$twitter_oauth_token_secret           = get access secret key from db
if($twitter_oauth_token_secret!='' && $twitter_oauth_token!='')
{
             $connection = new TwitterOAuth(CONSUMER_KEY,                       CONSUMER_SECRET, $twitter_oauth_token, $twitter_oauth_token_secret);
            $my_update = $connection->post('statuses/update',               array('status' => $statusText));
}



?>
Out put in Twitter wall like, Hope it will help you, please comment if you have any question on this.




6 comments:

  1. Being new to the blogging world I feel like there is still so much to learn. Your tips helped to clarify a few things for me as well as giving..
    Study Abroad Consultants in Chennai | Study in Germany Consultants in Chennai | Germany Education Consultants in Chennai

    ReplyDelete
  2. Superb. I really enjoyed very much with this article here. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article.thank you for sharing such a great blog with us. expecting for your.
    Digital Marketing Company in India
    seo Company in India

    ReplyDelete
  3. Very useful article about TWITTER concepts..It is very easy to understand about TWITTER for beginners and learners..keep posting useful posts like this..
    Engineering Colleges In Chennai , Nautical Science Colleges In Chennai

    ReplyDelete
  4. This is really nice because it well informative for me and hope for others also keep it continued so that we can get benefits.Hotels in Kumbakonam,Kumbakonam Hotels

    ReplyDelete
  5. I simply want to say I’m very new to blogs and actually loved you’re blog site. Almost certainly I’m going to bookmark your blog post . You absolutely come with great well written articles. Thanks a lot for sharing your blog.
    Architects in Chennai

    ReplyDelete
  6. Thank you for useful blog to share your page and get more topic to be display our next blog For more details:Find Girlstrichy matrimony,bharat matrimony,SC Matrimony,Brahmin Matrimony.

    ReplyDelete