I am able to tweet messages and images to twitter using a single application and one account. Just for testing purposes, I would like to know if there is a way to tweet to multiple accounts using the same application. I was thinking that we should use the access token of every single account and its corresponding secret as well. Can anyone help with this if what I am thinking is possible??
require_once('twitter/codebird-php/src/codebird.php');
\Codebird\Codebird::setConsumerKey("xxx","xxxx");
$cb = \Codebird\Codebird::getInstance();
$cb->setToken("xxxx", "xxxxxxxxx");
$params = array(
'status' => $comments,
'media[]' => 'http://spe.atdmt.com/ds/NMMRTRUMTCRF/Azure_070114/dearazure_banner_hotub_728x90.gif'
);
$reply = $cb->statuses_updateWithMedia($params);
Just change the token after posting (->setToken) and then post again.
Related
Is it possible to send automatic tweets from laravel like user.
User must be logged by my twitter API, and then can I send tweet as him?Of course he must accept this action. I must know when user tweets my page.
Can it work like facebook share? Is there tools for this?
Sorry for my english.
Thanks for all answer.
PS.
I do not mean this package http://vegibit.com/send-a-tweet-with-laravel/ .
I need send tweets to user table.
I have found the ThuJohn package to be the winner at this type of work.
https://github.com/thujohn/twitter
Simple to use with various options, such as
Send a tweet realtime without media:
Route::get('/send-tweet-no-media', function()
{
return Twitter::postTweet(['status' => 'Laravel is beautiful', 'format' => 'json']);
});
Send a tweet realtime with media:
Route::get('/send-tweet-with-media', function()
{
$uploaded_media = Twitter::uploadMedia(['media' => File::get(public_path('filename.jpg'))]);
return Twitter::postTweet(['status' => 'Laravel is beautiful', 'media_ids' => $uploaded_media->media_id_string]);
});
You can also do various other things, such as login, You can take it an extra level and easily store the users token & secret to your users table and do scheduled posts.
Once you have stored the users token & secret you can tweet scheduled posted for them like this:
//Get the Users token & from your User Table (or where ever you stored them)
$token = $user->token;
$secret = $user->secret;
//This line resets the token & secret with the users
Twitter::reconfig(['token' => $token, 'secret' => $secret]);
//This line posts the tweet as the user
Twitter::postTweet(['status' => 'test', 'format' => 'json']);
Use this https://twitteroauth.com/ package.
Push in your console composer require abraham/twitteroauth
When all installed then you should add
use Abraham\TwitterOAuth\TwitterOAuth; to your class.
Now in function you must create connection with your api.
$connection = new TwitterOAuth(
CONSUMER_KEY, // Information about your twitter API
CONSUMER_SECRET, // Information about your twitter API
$access_token, // You get token from user, when him sigin to your app by twitter api
$access_token_secret// You get tokenSecret from user, when him sigin to your app by twitter api
);
If you created connection then you can send post as user.
For example:
$connection->post("statuses/update", ["status" => "My first post!"]);
Im using this package https://github.com/thujohn/twitter to authorize users. I am able to authorize multiple users and get their data from twitter. I am struggling to post tweets to multiple users twitter accounts. Everytime I try to post it will only tweet to 1 users account. How can I post to multiple users accounts after authorization?
Here is the code I have tried. I save the user's tokens in the database and then grab it and put it in the session. :
Route::get('tweet', function(){
$token = Input::get( 'oauth_token' );
$verify = Input::get( 'oauth_verifier' );
$screen_name = DB::table('profiles')->where('oauth_token', $token)->pluck('screen_name');
$tweet_text = Input::get('tweet_text');
Session::put('oauth_request_token', $token);
Session::put('oauth_request_token_secret', $verify);
Session::get('oauth_request_token');
Session::get('oauth_request_token_secret');
dd( Twitter::postTweet(['status' => $tweet_text, 'format' => 'json']) );
});
I figured out what I was doing wrong incase anyone else runs into this problem. You have two pairs of tokens. The package I used calls them both oauth_token and oauth_token_secret but in two different arrays. I used the wrong pair and so It would only post to the last authenticated account. Make sure you use access_token pair and store them for later use. Which you can then use to post to the right/multiple accounts.
I am the owner and admin of a LinkedIn company page: https://www.linkedin.com/company/{id}/.
I want to connect to LinkedIn and get return a JSON-feed with latest 10 posts on my company wall to display on my website so I touch on the service https://api.linkedin.com/v1/companies/{id}/updates?format=json.
The JSON is outputted in linkedin.php. This file is then included in my web page, say index.php.
I have registrered an app at https://developer.linkedin.com. I have entered my Client ID and Client Secret in PHP-LinkedIn-SDK available here https://github.com/ashwinks/PHP-LinkedIn-SDK.
I followed the developer documentation I need to authenticate first. When I run linkedin.php I am redirected to sign into my LinkedIn profile. I have to finish this step in order to touch the service above.
With the current solution my users will have to login into LinkedIn when they access my website.
How can I access a list of my company's LinkedIn posts without prompting my users to sign in?
Thanks.
1. Generate your access token
Follow the documentation https://github.com/ashwinks/PHP-LinkedIn-SDK to create a login link.
2. Save your access token
Once you get it, it will be available for 60 days. Save it into your database.
3. Fetch your company posts
You can use the same access token to fetch company contents
$li = new LinkedIn(...);
$li->setAccessToken(YOUR_ACCESS_TOKEN);
$posts = $li->get('/companies/YOUR_COMPANY_ID/updates/');
4. Manage response
Cache or display the response after parsing it.
Hope that helps,
Use https://packagist.org/packages/linkedinapi/linkedin
$li = new LinkedIn(
array(
'api_key' => 'yourapikey',
'api_secret' => 'yourapisecret',
'callback_url' => 'https://yourdomain.com/redirecthere'
)
);
//Get the login URL - this accepts an array of SCOPES
$url = $li->getLoginUrl(
array(
LinkedIn::SCOPE_BASIC_PROFILE,
LinkedIn::SCOPE_EMAIL_ADDRESS,
LinkedIn::SCOPE_NETWORK
)
);
/*LinkedIn will redirect to 'callback_url' with an access token as the 'code' parameter. You might want to store the token in your session so the user doesn't have to log in again*/
$token = $li->getAccessToken($_REQUEST['code']);
$token_expires = $li->getAccessTokenExpiration();
//Make a request to the API
$info = $li->get('/people/~:(first-name,last-name,positions)');
$li = new LinkedIn(
array(
'api_key' => 'yourapikey',
'api_secret' => 'yourapisecret',
'callback_url' => 'https://yourdomain.com/redirecthere',
'curl_options' => array(
CURLOPT_PROXY => '127.0.0.1:80',
),
)
)
I want my website to automatically post status updates to a particular twitter account using OAuth in PHP.
I test this using a URL
www.mysite.com/update_status
but it asks me for "user name" and "password", which is fine when I am testing it. But my website will not be able to insert this user name and password before posting the status update.
So the question is how can a website which is in the server, automatically post a status update to an account without user filling out the user name and password.
Is there any way to bypass this? I tried saving oAuth tokens, but it's not working.
Thank you for your answer in advance!
My recommendation:
1) Use a PHP library like http://github.com/abraham/twitteroauth.
2) Select your app on http://dev.twitter.com/apps and click on "My Access Token".
3) Us that access token as described on http://dev.twitter.com/pages/oauth_single_token.
Just tried this and it WORKS! And its SO SIMPLE to use!!
http://ditio.net/2010/06/07/twitter-php-oauth-update-status/
Got it working in under 5mins.
xAuth is able to do that, but Twitter only allows it for desktop and mobile apps.
In case you wanna try it, read this article and the API docs.
Try it with zend framework. As of version 1.10.8 minimal code required to post on Twitter is:
$token = new Zend_Oauth_Token_Access;
$token->setParams(array(
'oauth_token' => 'REPLACE_WITH_TOKEN',
'oauth_token_secret' => 'REPLACE_WITH_TOKEN_SECRET'
));
$twitter = new Zend_Service_Twitter(array(
'consumerSecret' => 'REPLACE_WITH_CONSUMER_SECRET',
'accessToken' => $token
));
$response = $twitter->status->update('REPLACE WITH MESSAGE');
All tokens and secrets can be accessed after registering your application on http://dev.twitter.com
Any advice on how to get MySpace or Orkut info such as birthdate from a person's profile using OAuth using the OpenSocial PHP Client library?
I am lost on the process, and the tutorials are complicated. Any simple code would be helpful!
Thanks.
First, you need the PHP Open Social Client.
As shown in the documentation, you will need to create an osapi container, which requires a provider and an authorization object. In the case of MySpace, it would look something like:
$provider = new osapiMySpaceProvider();
$auth = new osapiOAuth2Legged("<consumer key>", "<consumer secret>", "<OpenSocial user ID>");
$osapi = new osapi($provider, $auth);
I'm afraid I have no idea what goes in the auth area, whether it's those actual strings or something that you should already know. I'm sure the page I got it from has more info. But either way, once you have the osapi container, you can then make requests for user info:
$profile_fields = array(
'aboutMe',
'displayName',
'bodyType',
'currentLocation',
'drinker',
'happiestWhen',
'lookingFor'
);
$self_request_params = array(
'userId' => $userId, // Person we are fetching.
'groupId' => '#self', // #self for one person.
'fields' => $profile_fields // Which profile fields to request.
);
$result = $osapi->people->get($self_request_params), 'self');
Here's a nice tutorial: http://wiki.opensocial.org/index.php?title=Social_Website_Tutorial