Google trends Public Holidays Coupon Code Code Compiler

How to Auto Post on Twitter with PHP


Nov 17, 2019

Twitter provide API which we can use for auto post on twitter. So here are the demo for the use of twitter API. This is very simple process. You will have to follow only few step for using the twitter API.

first of all we have to create an account on twitter and then we have to go on twitter developer account https://dev.twitter.com/apps. and create a twitter app for post. This is very simple, after filled all required fields your twitter application will be ready for use. After the creation of twitter app, we will get the CONSUMER_KEY, CONSUMER_SECRET, OAUTH_SECRET keys for entering in the index file.

Now ypu can use login with twitter and get oauth access token and oauth secret key for post on twitter account.

Now we can download the SDK from the GitHub. Here is the link for download SDK https://github.com/jublo/codebird-php.


require_once('Twitter/src/codebird.php');
\Codebird\Codebird::setConsumerKey(CONSUMER_KEY_XXXXX, CONSUMER_SECRET_XXXXXXXXX);
$cb = \Codebird\Codebird::getInstance();
$cb->setToken(OAUTH_ACCESS_TOKEN, OAUTH_SECRET_XXXXXXXX);
$image = "IMAGE_URL_TO_UPLOAD_ON_TWITTER";
$reply = $cb->media_upload(array(
    'media' => $image
));
$mediaID = $reply->media_id_string;
$params = array(
    'status' => 'MSG_FOR_TWEET',
    'media_ids' => $mediaID
);
$cb->statuses_update($params);

Copyright 2024. All rights are reserved