Get my own full profile with LinkedIn API - php

For testing purposes, I'd like to get my own full profile datas from LinkedIn API.
So far my code looks like this :
// Fill the keys and secrets you retrieved after registering your app
$oauth = new OAuth("APIKEY", "SECRETKEY");
$oauth->setToken("Token OAuth", "Secret User OAuth");
$oauth->disableSSLChecks();
$params = array();
$headers = array();
$method = OAUTH_HTTP_METHOD_GET;
// Specify LinkedIn API endpoint to retrieve your own profile
$url = "https://api.linkedin.com/v1/people/~:(first-name,last-name,headline,location:(name),skills:(name),educations:(id,school-name,field-of-study))?format=json";
// By default, the LinkedIn API responses are in XML format. If you prefer JSON, simply specify the format in your call
// $url = "https://api.linkedin.com/v1/people/~?format=json";
// Make call to LinkedIn to retrieve your own profile
$oauth->fetch($url, $params, $method, $headers);
$oProfile = json_decode($oauth->getLastResponse());
var_dump($oProfile);
Although I am getting basic profile informations (firstName,headline etc...) but when it comes to full profile informations I get an object with '...' as value everytime, although the informations exist.
I have r_fullprofile ticked in my LinkedIn app interface, so I don't know what I have to do to get these values.

I tried your query with my own account. It looks you issue is with the skills field.
You can see in the LinkedIn API documentation that skills are made up of a skill, and each skill has a name. If you only want the name returned the proper way to ask for it is
skills:(skill:(name)), whereas your request asks for skills:(name).
Here is an updated request for you:
GET https://api.linkedin.com/v1/people/~:(first-name,last-name,headline,location:(name),skills:(skill:(name)),educations:(id,school-name,field-of-study))?format=json

Related

Using Twitch's API to get multiple channels with one request

I am using Twitch's API to request some details about a user, in particular I need to get their: twitch user, channel, live channel
I am having no problem getting any of their details, I have it set up so I can get a bulk amount of users with one request. The same with their live channels. But with just getting channel information, according to Twitch's API I must send a request per user. I can't see anyway to get a bulk list of channels
For example, using the code posted below, I can get 10-100s of users twitch user data in one simple request
But when I try to send too many requests I get blocked from their API
Code for getting bulk twitch user data
public static function setTwitchUserBulk($users)
{
// Key by their twitch_id
$users = $users->keyBy('twitch_id');
$twitch_key = env('TWITCH_KEY');
$url = 'https://api.twitch.tv/helix/users?';
foreach($users as $user) {
$url .= 'login='.$user->twitch_username.'&';
}
$data = \App\CustomHelper\ZarlachTwitchHelper::_basicCURL($url, array(
'Client-ID' => $twitch_key,
));
$data = json_decode($data, true);
if(isset($data['data'])) {
$data = $data['data'];
foreach($data as $twitchUser) {
if(isset($users[$twitchUser['id']])) {
// ... handle and store their data
}
}
}
}
According to Twitch's API, I must use this URL to get their channel
GET https://api.twitch.tv/kraken/channels/<channel ID>
Where as, when I get their twitch user, I can simply keep adding parameters onto the url to set the users i want to fetch
GET https://api.twitch.tv/kraken/users?login=<user IDs>

graph api notifications returns empty data

im building a facebook app and i want to notify the user
https://developers.facebook.com/docs/games/notifications
im using facebook php sdk
what i do:
user auths the app and accepts permission
i get the accesstoken like:
$facebook->getAccessToken()
and then i generate a long-time token like:
public function generateLongTimeToken($token){
$long_time_token_req_body = array(
"grant_type"=>"fb_exchange_token",
"client_id"=>$this->facebookOptions["appId"],
"client_secret"=>$this->facebookOptions["secret"],
"fb_exchange_token"=>$token
);
$query = http_build_query($long_time_token_req_body);
$lttreq = file_get_contents("https://graph.facebook.com/oauth/access_token?".$query);
$lttresp = parse_str($lttreq, $output);
if ( array_key_exists("access_token", $output)){
$this->logger->info("Facebook-app: Successfuly generated long_time_token");
return $output["access_token"];
}else {
$this->logger->err("Facebook-app: generating oauth long_time_token failed \n".$lttreq);
return false;
}
}
some later i use this token for background processes to post on the users wall and them all work fine
now i also want to notificate the user like that :
public function notifyUser($message,$facebookClientId,$token){
$appsecret_proof= hash_hmac('sha256', $token, $this->facebookOptions["secret"]);
$req_body = array(
"access_token"=>$token,
"appsecret_proof"=>$appsecret_proof,
"href"=>"/index",
"template"=>$message,
"ref"=>"post"
);
$query = http_build_query($req_body);
$url = "https://graph.facebook.com/".$facebookClientId."/notifications?".$query;
$lttreq = file_get_contents($url);
return $lttreq;
}
but when i try to notify the user i always get empty data back
when i open the url in browser with all parameters facebook returns the same
{
data: [ ]
}
so i have no idea whats going on,when i look on SO i only find about people posting to sites but i want to notify the user itself
thanks for any help
First, from the Facebook docs:
Currently, only apps on Facebook.com can use App Notifications.
Notifications are only surfaced on the desktop version of
Facebook.com.
Also, an App Token is needed, not a User Token.
Btw, file_get_contents is very bad, use CURL for Facebook. May be another reason why it does not work. A basic example of using CURL with the Facebook API: http://www.devils-heaven.com/extended-page-access-tokens-curl/
Additional Info: I recently wrote a blogpost about App Notifications, it is in german but the small code part may be interesting for you: http://blog.limesoda.com/2014/08/app-notifications-facebook-apps/

Getting JSON data from Twitter using ID in PHP

I have a following script which helps me getting data in json format from a particular Facebook ID.
Here's the code
if($recipy_info[0]['social_media']=='facebook')
{
$pageContent = file_get_contents('https://graph.facebook.com/'.$recipy_info[0]['post_userid'].'?fields=id,name,picture,birthday');
$parsedJson = json_decode($pageContent);
//$facebook_info= https://graph.facebook.com/100003384367738?fields=id,name,picture,birthday
}
Now the issue is that I want to have a similar work for Twitter, I don't have screen name, all I have is just the id 1897279429.
I have a url https://api.twitter.com/1.1/trends/1897279429.json, but it gives me this error:
{"errors":[{"message":"Bad Authentication data","code":215}]}
How can I sort my problem?
I want to get JSON data from the id I have.
Since API 1.1 you are required to authenticate first before you can get the public tweets from a user. Please take a look at the API documentation here: https://dev.twitter.com/docs

Get wall feed from a public Facebook page using Graph API - is it really this complex?

I have started off by reading Displaying Facebook posts to non-Facebook users which is of some use but I cannot believe it is this difficult to get a public feed from Facebook.
The page I want a feed from is public, you do not need to be logged into get to it.
Am I right in presuming that I need an access_token to get to this information, attempting to access the URL without results in an OAuth error.
So the flow should be like this (massively, overly complex):
Authenticate using a user (what if the user isn't on Facebook?)
Some complex OAuth nonsense - just to read the feed, I do not even want a like button or post to wall functionality
Get the feed using a PHP request to the correct URL with the user's access_token
Render the feed
Assuming the user isn't on Facebook, what do you do, use a generic app to get the feed?
Hardcode an auth request to Facebook using my generic app's ID and secret
Some complex OAuth nonsense
Get the feed using a PHP request to the correct URL with the app's access_token
Render the feed
Oh no, the auth has expired, re-auth and capture this new access_token for use in future requests.
This seems really complex for no reason other than Facebook wants to know EVERYTHING that is going on, it'd be easier to do a cURL and scrape the content from the public URL using XPath.
Any help on this would be great.
Thanks,
Jake
EDIT
An edit to show this is not an exact duplicate.
I had this working with an access_token in place, but now it fails, the token has expired and I can no longer use it to obtain information from the public wall.
I attempted to extend the expiration date of this token using the methods mentioned in other posts but this didn't work and the expiration was not extended - we are now here, with an invalid token and no further along.
It seems that the manual process of having to approve the OAuth request means that it is impossible to programatically get the feed of a public page.
Two years later, you can programmatically do this with a Facebook App (an example using PHP and Slim): https://developers.facebook.com/apps/
$base_api="https://graph.facebook.com/";
$client_id="XXXXXX";
$app_secret="XXXXXX";
//get a profile feed (can be from a page, user, event, group)
$app->get('/feed/:profileid/since/:start_date', function ($profile_id,$start_date) {
$start_time=date('m/d/Y h:i:s',$start_date);
$request = new FacebookRequest(
getSession(),
'GET',
'/'.$profile_id.'/feed?since='.$start_time
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
//do something with $graphObject
});
function getSession(){
$session = new FacebookSession(getAccessToken());
return $session;
}
function getAccessToken(){
global $base_api, $client_id, $app_secret;
$url=$base_api."oauth/access_token?client_id=".$client_id."&client_secret=".$app_secret."&grant_type=client_credentials";
$str = file_get_contents($url);
$token = str_replace ( "access_token=" , "" , $str );
return $token;
}
I have some success with reading in the direct feed without tokens etc.
(using magpie, simplepie or querypath or similar).
http://www.facebook.com/feeds/page.php?format=rss20&id=........
http://www.facebook.com/feeds/page.php?format=atom10&id=........
found on: http://ahrengot.com/tutorials/facebook-rss-feed/
Facebook has changed how to retrieve a public Facebook page's feed since the other answers were posted.
Check out my answer/question. It's not PHP, but it provides the URLs and process you need.

Get user details from openid

I'm using lightopenid as the login system for a site and after successful login, I need the user's details like his first name, last name, email and date of birth..
How can I get this information from his openid? Suppose for google, I'm using the authentication url as: https://www.google.com/accounts/o8/id
Then after the validate() method returns 1, I'm redirecting the user to another page in my site. But how can I fetch the details of the user after login ?
FYI, I'm using openid for google, yahoo and aol.
And for facebook, I'm using graph api and for twitter, I'm using twitter oauth. Is there any way of fetching user data with these too? Please suggest.
Just read the manual:
http://code.google.com/p/lightopenid/wiki/GettingMoreInformation
$openid->required = array('namePerson/friendly', 'contact/email');
$openid->optional = array('namePerson/first');
before calling $openid->authUrl()!
Then
$openid->validate();
$userinfo = $openid->getAttributes();
$email = $userinfo['contact/email'];
$firstName = $userinfo['namePerson/first'];
You need to add a parameter to specify that you also want to receive data back from the OpenID request.
I append the following to my OpenID requests to get the email details.
&openid.ns.ax=http%3A%2F%2Fopenid.net%2Fsrv%2Fax%2F1.0&openid.ax.mode=fetch_request&openid.ax.type.email=http://axschema.org/contact/email&openid.ax.required=email
The first part specifies the namespace being used for the extended data.
The second part specifies that we are making a fetch request for the data.
The third part specifies the schema we are using for the email.
And the final part is specifying that we require the email to be returned.
I have tested this with Google and it works fine. I do not have the other accounts, so have not tested it for those.
OAuth and Facebook Graph API will have there own formats, so I am not sure on those ones.
$openid->identity = 'https://www.google.com/accounts/o8/';
// use the following line to obtain the required details. These are the only details that google mail provides.
$openid->required = array('namePerson/friendly', 'contact/email' , 'contact/country/home', 'namePerson/first', 'pref/language', 'namePerson/last');
header('Location: ' . $openid->authUrl());
Seemingly lightopenid provides a method for that:
$openid->validate();
$userinfo = $openid->getAttributes(); // associative array
It returns either SimpleReg or "Attribute Exchange" data. But only if the user agreed to that, I would hope.

Categories