LinkedIn Company Feed - php

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',
),
)
)

Related

How to display LinkedIn feeds on my website in php?

I would like to show my company Linkedin feed on my website (a WordPress site),For fetching LinkedIn feeds, i created LinkedIn company page and post some feeds on that page. After that i created app on https://www.linkedin.com/developer/, i and got client ID, client Secret Key, i also got access token of my app. But i'm not understanding, how can i make LinkedIn API so that i can display LinkedIn feeds on my website. Actually i don't want to display feeds by iframe way. I want display feeds on my custom html. I have tried Using PHP LinkedIn SDK as following.
$li = new LinkedIn(array(
'api_key' => "client secret",
'api_secret' => "client ID",
'callback_url' => "redirecturl"
));
$token = $li->setAccessToken('Your access token');
$feeds = $li->fetch('GET', '/v2/companies/company-id/updates?event-type=status-update&start=0&count=6&format=json');
$posts = $li->get('/companies/79097881/updates/');
$pages = json_decode(file_get_contents($posts));
echo "<pre>"; print_r($pages);
But i didn't get anything. So please provide me some solution.

ETSY Api PHP Obtaining Token Credentials

I'm using y0lk package to help me with OAuth1 and ETSY App, I managed to get the temporary credentials, but can't get my hand on Access tokens.
here's what I do :
$client = new Etsy([
'identifier' => '*********************',
'secret' => '*********',
'scope' => 'listings_r transactions_r',
'callback_uri' => 'http://*********.loc/slider/'
]);
$tempCred = $client->getTemporaryCredentials();
$tmpSecret = $tempCred->getSecret();
$tmpId = $tempCred->getIdentifier();
// Redirect to Etsy Autorisation login page
$redirect_url = $client->getAuthorizationUrl($tempCred);
$accessTokens = $client->getTokenCredentials($tempCred, $tmpId, $_GET['oauth_verifier']);
Ok, I don't know how to do, because to obtain the oauth verifier ( and do the $_GET['oauth_verifier']), I have to go by the login page, and then, to get the access token, I need my temp credentials, but to get then I 'll have to go again by new Etsy and this is why I always got the token revoked error..
I'm beginner, in PHP and with API, if someone see other mistakes in my way to do this, feel free to point them out for me :)
Thank you for your time.

Laravel send tweet as user

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!"]);

How to retrieve user's newsfeed list (VK.com)?

I am using following php code :
$vk = new VK($app_id, $api_secret);
$user_wall = $vk->api('newsfeed.get', array(
//'owner_id' => $o->profile_uid,
'count' => 100,
'filters' => 'post,photo,wall_photo,friend',
'access_token' => $o->profile_token
));
echo '<pre>';
print_r($user_wall);
exit;
I am getting error when trying above code. I have successfully completed auth and stored user profile info in mysql table. I notice that when I see Api.Console permission in App> Setting, I see Access the Wall permission. But in application I used to retrieve data, I do not see this permission.
Error description : Permission to perform this action is denied
Error code : 7
The documentation is poorly described. Even which field is required or optional I can not determine. And what is difference between wall.get with filter "others" vs newsfeed.get ?
LOGIN CODE:
$AuthURL = $vk->getAuthorizeURL('notify,friends,photos,audio,video,docs,notes,pages,status,offers,questions,wall,groups,notifications,stats,ads,offline', $redirect_uri);
AUTH CODE:
$vk_code = $_REQUEST['code'];
$vk = new VK($app_id, $app_secret);
$access_token = $vk->getAccessToken($vk_code, $redirect_uri);
$uid = $access_token['user_id'];
$token = $access_token['access_token'];
$user_info = $vk->api('users.get', array(
'user_ids' => $uid,
'fields' => 'nickname, screen_name, sex, bdate (birthdate), city, country, timezone, photo, photo_medium, photo_big, has_mobile, contacts, education, online, counters, relation, last_seen, activity, can_write_private_message, can_see_all_posts, can_post, universities, counters'
));
First you must register application: vk.com/editapp?act=create
Then you need get authorize code. To do this follow link:
oauth.vk.com/authorize?client_id={APP_ID}&scope={API_SETTINGS}
Where {APP_ID} — your application id (see on app settings page),
{API_SETTINGS} — access rights requested by your app (through comma). If need infinite token use key "offline". For newsfeed need use key "wall,friends,offline".
Opens page. Copy string in URL AFTER #code=
Later you need get access token. Go to link:
https://oauth.vk.com/access_token?client_id={APP_ID}&client_secret={API_SECRET}&code={CODE}
Where {API_SECRET} — secret application key (see on app settings page),
{CODE} — code that was copied in step 2.
Copy access_token.
To get newsfeed data request link:
https://api.vk.com/method/newsfeed.get.xml?access_token={ACCESS_TOKEN}
Where {ACCESS_TOKEN} — token that was in step 3.
NOTE: USE HTTPS WHEN USING THIS ACTIONS
You need the following rights to call this method: wall and friends. (Read more on rights)
You must generate authorization with wall and friends...
https://oauth.vk.com/authorize?client_id=APP_ID&scope=wall,friends,offline
Just replace APP_ID with your appilication and then get your token

How to post programatically to your own facebook page?

My situation is the following.
I am the owner of a facebook app,and a facebook page.I would like to programatically(from code) post to this facebook page.
As far as I know I need a facebook app to do that so I created one.
I am using the facebook php sdk and code igniter.(I am not using the javascript sdk).
I have the facebook object.I printed it's methods and tried printint the user id while I was logged into facebook.
This did not work.
My questions are the following:
1)Why does it not work to print the facebook id?
2)What is the most simplest solution to programatically post to my facebook page ?(from my app,or from my user)
What am I doing wrong ?
This is my code
$config = array(
'appId' => 'xxxx',
'secret' => 'xxxx',
'cookie' => true,
);
$this->load->library('facebook', $config);
echo '<pre>';print_r(get_class_methods($this->facebook));
$id = $this->facebook->getAppId();
$secret =$this->facebook->getApiSecret();
$uri = "http://tipsterscorner.com/stats/display/facebook1";//callback_url se pare ca nu e bun
//i build the facebook url.If I use this in the browser ,I get a series of popups(do you allow the application to blabla)
//I read somewhere that if I change the last parametere to code,and use curl,I will get the token in the response
//printed on the screen of the return url,but that does not happen
$facebook_url = "https://www.facebook.com/dialog/oauth?`client_id=$id&client_secret=$secret&redirect_uri=$uri&scope=publish_stream,offline_access,read_stream,manage_pages&response_type=token";`
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $facebook_url,
CURLOPT_USERAGENT => 'Codular Sample cURL Request'
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
This is the url.
http://tipsterscorner.com/stats/display/facebook1
Thank you very much.
To post on facebook by yourself and on behalf of other's using the app you need to obtain user access token. There are two kinds of Access Tokens namely App Access Token and User Access Token. When app is posting on user's behalf User Access Token is required. User Access Token is generated when a User gives permissions for the app(The dialog popup which you experienced when entering the facebook url in browser). Its solely upon user whether or not to grant permission to the app to post on their behalf. App should be developed to handle both the situations. Once User have given permission(Basic Permission which includes all publicly available info of the user), user access token will be generated. You can either store it in database table or in SESSION. Sometimes user access tokens may become invalid and new token has to be retrieved. During that time curl can be used to retrieve because user has already granted permission for the app.
http://developers.facebook.com/blog/post/2011/05/13/how-to--handle-expired-access-tokens/

Categories