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!"]);
Related
I have the Xero API setup and the OAuth flow working. I have linked up the "Demo Company UK" as the tenant (Organisation) and have granted my user with Adviser • Contact bank account admin, Payroll admin • Expenses (Admin) permissions (which appears to be the highest level) located here: https://go.xero.com/Settings/Users but I still get the following error. "You are not permitted to access this resource" I have added all the scopes that should cover the requests and have a valid access token but still no good.
'client_id' => env('XERO_CLIENT_ID'),
'client_secret' => env('XERO_CLIENT_SECRET'),
'redirect_uri' => env('XERO_REDIRECT_URI'),
'scope' => 'openid email profile offline_access accounting.transactions accounting.contacts accounting.contacts.read accounting.reports.read',
Example function making a basic call to get the users within the account. The connection to Xero is fine but as soon as I try to request any data the same error is thrown.
public function testXero() {
$xeroAccessToken = GlobalSetting::where('name', '=', 'xero_access_token')->first();
$xeroTenantOrganisation = GlobalSetting::where('name', '=', 'xero_tenant_organisation_id')->first();
$xero = new XeroApp(
new AccessToken(
array(
'access_token' => json_decode($xeroAccessToken->value)->id_token
)
), $xeroTenantOrganisation->value
);
//dd( $xero ); //we have a succesfull connection here...
# Retrieve all contacts
$contacts = $xero->contacts()->get();
dd($contacts); //error "You are not permitted to access this resource".
}
Has anybody encountered this issue?
The issue is that I was passing id_token when making a new XeroApp class instance. I failed to see all the other objects in the JSON object stored in the Database (very large). There is an actual access_token that is stored along with some other useful bits of information that I make within my call.
$xero = new XeroApp(
new AccessToken(
array(
'access_token' => json_decode($xeroAccessToken->value)->access_token,
'refresh_token' => json_decode($xeroAccessToken->value)->refresh_token,
'expires' => json_decode($xeroAccessToken->value)->expires,
)
), $xeroTenantOrganisation->value
);
$contacts = $xero->contacts;
dd($contacts);//RESULTS!!! YES
I will keep this thread open just in case it helps anyone out.
Nice save Nick - yes the id_token can be used for things like "Sign up with Xero" which can be a huge advantage if your business operations is core to financial data.
https://developer.xero.com/documentation/oauth2/sign-up
It essentially enables you to provision accounts in your system (using the decoded ID token name / email) and sync their Xero data in a single flow. We've see partners significantly reduce drop off for new signups because of it.
All that said, a valid access_token and the tenant_id are the things you need to make authorized API calls.
I had same problem and I recognized that I had wrong tenant id.
You have to be sure about all credentials.
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',
),
)
)
How can I log into Facebook without a login form?
I've created an application which posts wall posts to one of my pages automatically (with a cron job).
But it needs login. I've done everything with the PHP SDK 3.1 and it works if I am logged into Facebook by my browser. But it does not work on my hosting and this is important for me because it is "scheduled auto poster".
Is it possible with the PHP SDK or JavaScript SDK or anything?
PS: Logging in with cURL does not work (code: http://www.daniweb.com/web-development/php/code/290893).
I use PHP SDK 3.1.
Here is my code:
require 'sdk/facebook.php';
$facebook = new Facebook(array(
'appId' => $bilgi_appID,
'secret' => $bilgi_appSecret,
'fileUpload' => true,
'cookie' => true // enable optional cookie support
));
$facebook->setFileUploadSupport(true);
$args = array(
'message' => $bilgi_fotoMesaji,
"access_token" => $access_token,
"image" => $file
);
$data = $facebook->api('/'.$bilgi_sayfaninAlbumIDsi.'/photos', 'post', $args);
if ($data)
print_r("basariyla yuklendi...");
This works when I am logged in Facebook.
But how can I post a photo or post while I am logged out? It redirects login page.
Scheduled auto-posting is available when requesting the publish_stream permission, even when the user is actively using your application. From Permissions Reference:
publish_stream
Enables your app to post content, comments, and likes to a user's stream and to the streams of the user's friends.
With this permission, you can publish content to a user's feed at any
time. However, please note that Facebook recommends a user-initiated
sharing model. Please read the Platform
Policies to ensure you
understand how to properly use this permission.
Using graph api publish_stream permission: together with offline_access permission:
As described here and here. However for some reason one of the following two things are happening:
I am trying to post to a facebook user which is not currently logged in, following an action of a user which is curently logged in (e.g. telling user #1 that user #2 visited their farm in farmville, but user #1 is not logged in, while user #2 is. And they are not necessarily friends).
When I tried this using the following code, the post was not created when users #1 and #2 were not friends (first problem), and when they were friends, the post was being created, but seemed like user #2 was posting it on user #1's wall (second problem - this is NOT what I am trying to do, I want it to be anonymous).
See the first code I used:
$post_id = $facebook->api('/' . $user1_id . '/feed/', 'post', array(
'message' => 'Someone just visited your farm',
'link' => 'http://example.com',
'picture' => 'http://example.com/img/picture.jpg',
'caption' => 'Visit farms!'
));
So I tried to use the access token of user #1, which he gave me when he was logged in, and the application is supposed to be able to post on their wall even when they are offline (even without offline_access permission - see here facebook's documentation: "you can publish... without requiring offline_access". At any rate, when I am adding the access_token to the array as a parameter (see the code below), no post is being created at all:
$post_id = $facebook->api('/' . $user1_id . '/feed/', 'post', array(
'access_token' => $user1_access_token,
'message' => 'Someone just visited your farm',
'link' => 'http://example.com',
'picture' => 'http://example.com/img/picture.jpg',
'caption' => 'Visit farms!'
));
What should I do?
gain, I am simply trying to publish to user's wall that is NOT logged in, but who gave me the publish_stream permission, a post from the application, not any other user, telling this user that someone (anonymously) has "visited their farm" (or created some action associated with them).
Thanks everyone.
this is just a recommend & i'm not sure this be the answer
Destroy all of the sessions (or use your browser in private mode -for Firefox )
& then visit sender page Like this
example.com/postfarm.php
maybe when you visit the page normally the app gets your access_token & tries to post as you
PS:better way
use this code & you dont need to destroy sessions anymore
include_once ('src/facebook.php');/// include sdk
////// config The sdk
# $facebook = new Facebook(array(
'appId' => 'XXXXXXX',
'secret' => 'XXXXXXXXXXXXXX',
));
$facebook->destroySession();
try{
$post=$facebook->api('USER_ID/feed/','POST',array(
'message' => '$message',
'link'=>'http://apps.facebook.com/xxxxxxx/link.php?link=',
'picture'=> 'XXXXXXXXXX',
'name'=>'XXXXXX',
'description'=>'yes',
));
}
catch(FacebookApiException $e) {
echo $e->getType();
echo '<br />';
echo $e->getMessage();
}
For the "someone did something in a game and it's your turn", I believe what you're looking for is requests 2.0, specifically the "App to user" communication.
from: https://developers.facebook.com/docs/requests/
App to User Requests can be used to re-engage a user in your app and
can only be sent to users that have installed the app. For example,
notifying a user that something has changed since their last visit,
"10 of your friends are now online".
App to User Request are sent via the Graph API, for more information
see the apprequests docs. App to User Requests are only available for
Canvas apps, not websites, as accepting a request will direct the user
to the Canvas Page URL of the app that sent the Request.
from: https://developers.facebook.com/docs/guides/canvas/
App-generated requests: These requests can be initiated and sent only
to users who have authorized your app. You should use these requests
to update the bookmark count to encourage a user to re-engage in the
app (e.g., your friend finished her move in a game and it’s now your
turn).