Cronjob with Twitter
I want to send tweets from my users' twitter accounts using cronjob that s开发者_C百科igned up or connected to my site using twitter. But the problem is
Oauth keys are valid only while session is active, so storing oauth keys info of user's in database is useless (Am i right about this ? Not really sure, please correct me if i am wrong.)
So when the session ends, oauth key gets useless, and user needs to get new oauth keys.
And my question is : is there a way to do what i had written above ? Sending tweets from my users's twitter accounts.
I am newbie about this Twitter api thing, and also newbie on PHP. So i would like to get the "logic" of the way doing this or maybe some examples about it.
Twitter's OAuth 1.0a access tokens do not currently expire. You can save them in a database and they will keep working until the user revokes access.
I'd recommend "twitteroauth" library for OAuth on Twitter: https://github.com/abraham/twitteroauth. Here is an example code with the twitteroauth library.
<?php
// Load twitteroauth library.
require_once __DIR__ . '/twitteroauth/twitteroauth.php';
// Create a TwitterOAuth object.
$oauth = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
// Post a message.
$oauth->post('statuses/update', array('status' => "Hello, world!!"));
See: https://github.com/abraham/twitteroauth/blob/master/DOCUMENTATION
精彩评论