retrieve linkedin profile url from php api - php

I am using the Simple LinkedIn PHP Library to create a searching feature for an application. The user can search through LinkedIn and retrieve matched users information. As of right now the feature is working properly, but how can I parse the XML returned by the API and get the user's ID to create a link to their profile?
This is a sample of the array returned by the API call:
{
"numResults": 17325,
"people": {
"_count": 10,
"_start": 0,
"_total": 110,
"values": [
{
"firstName": "Leon",
"headline": "Digital Marketing | Mobile Marketing | Video Marketing | SEO/SEM | Digital Media Sales Trainer",
"id": "EFMHqoTad3",
"lastName": "E. Spencer",
"pictureUrl": "http://m3.licdn.com/mpr/mprx/0_jOgiHrinvW_afCa6PRDyHPXZBdvfi3a6xyWyHPXke7T0p5JQl4SfQ1KEMXzr86fopjxjFqnEf1I-"
},
If I understand correctly, a users profile url looks like http://www.linkedin.com/profile/view?id=156996610 so I should just be able to extract the ID from the API call and append to the view?id= query right? Can I do this with the SimpleXML PHP Library?

By XML I believe you mean JSON.
One way in php is by using the json_decode() function.
$url = file_get_contents("http://www.linkedin.com/profile/view?id=156996610");
$json =json_decode($url,true);
the second value "true" means it will be returned as an associative array.
Then you can access whatever you want from that response.
I.E a user ID..
$userID = $json['people']['values']['id'];
I suggest reading the json_decode() documentation to understand how this works.

Related

How to get public profile details from profile url using linkedin Rest API

I am trying to fetch whole information of user's by using linkedin public profile url But I am getting firstname, lastname and id in response.
How to get whole details.
I have tried on linkedin console
https://api.linkedin.com/v1/people/url=https%3a%2f%2fwww.linkedin.com%2fin%2fashishmishraoft?format=json
Response
{
"firstName": "Ashish",
"headline": "Sr PHP Developer at Myapp Generation.",
"id": "STaDeFHBBN",
"lastName": "Mishra"
}
LinkedIn does not return all possible member profile fields that are
available to you by default. There is a limited selection of
additional member fields that are also available to you which may be
relevant to your application. Refer to the Basic Profile Fields page
for a complete list of the basic member profile fields.
The following example demonstrates how to customize your API call to
request specific member profile fields that you wish to be returned
during the Sign In with LinkedIn workflow:
GET
https://api.linkedin.com/v1/people/~:(id,num-connections,picture-url)?format=json
sample api response:
{
"id": "1R2RtA",
"numConnections": 42,
"pictureUrl": "https://media.licdn.com/mpr/mprx/…"
}
https://developer.linkedin.com/docs/signin-with-linkedin
you can't get full_profile information from the basic linked in api. In order to get full_profile information you have to become partener with linked in.
https://developer.linkedin.com/partner-programs
if you want to get full information of r_basicprofile and r_emailaddress , make get request to following url with access token
https://api.linkedin.com/v1/people/~:(email-address,id ,first-name ,last-name ,maiden-name ,formatted-name ,phonetic-first-name ,phonetic-last-name ,formatted-phonetic-name ,headline ,location ,industry ,current-share ,num-connections ,num-connections-capped ,summary ,specialties ,positions ,picture-url ,picture-urls::(original) ,site-standard-profile-request ,api-standard-profile-request ,public-profile-url)?oauth2_access_token={YOUR_ACCESS_TOKEN}&format=json

Facebook graph API for videos not returning expected data

https://graph.facebook.com/v2.6/{video_id}/video_insights?metric=total_video_views&access_token={token}
I am using above link to get JSON details in PHP for a video object, however i am not able to get the required data w.r.t. the provided metric
data required : total_video_views
here is the FB for metric:
https://developers.facebook.com/docs/graph-api/reference/video/video_insights/
when i use
?metric=total_video_views
FB graph api gives
{
"data": [
],
"paging": {
"previous": "https://graph.facebook.com/v2.6/1034830076599589/video_insights?access_token=EAACEdEose0cBABRiFOqQuZBZBaKTZBW89XcMrTjakJseF76YjL2Hfj1rBRES2FAztFNMQWsMVdv9zwO90ISjx8efBVdfLZCyZBnHzDF5pTLNTgJPIH6PcBnb1YAD5XCWyvK6HIz3rHNP3xs3DfODSbUZCKZC2GkbkzYj7goFgfWVAZDZD&debug=all&format=json&method=get&metric=total_video_views&pretty=0&suppress_http_code=1&since=-86400&until=0",
"next": "https://graph.facebook.com/v2.6/1034830076599589/video_insights?access_token=EAACEdEose0cBABRiFOqQuZBZBaKTZBW89XcMrTjakJseF76YjL2Hfj1rBRES2FAztFNMQWsMVdv9zwO90ISjx8efBVdfLZCyZBnHzDF5pTLNTgJPIH6PcBnb1YAD5XCWyvK6HIz3rHNP3xs3DfODSbUZCKZC2GkbkzYj7goFgfWVAZDZD&debug=all&format=json&method=get&metric=total_video_views&pretty=0&suppress_http_code=1&since=0&until=86400"
}
}
but there is no field regarding the required metric i.e. total_video_views
am i making here some wrong request or something else ?
https://graph.facebook.com/v2.6/{video_id}/video_insights/total_video_views&access_token={token}
Should work for you.

Get Facebook user profile picture without them being logged into Facebook

In my database some users have Facebook IDs stored, as once they logged into my website via Facebook. For each of those users I would like to store a profile picture, which would be retrieved from their Facebook accounts.
Facebook PHP SDK specifies the following way to get a user picture:
/* PHP SDK v4.0.0 */
/* make the API call */
$request = new FacebookRequest(
$session,
'GET',
'/me/picture'
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* handle the result */
The problem is the $session param. Currently, I get the FacebookSession object after the user logs into my website via Facebook. However, for what I want to achieve, I don't have the session present.
Is it possible in PHP SDK to get Facebook user profile picture when having only the user ID, and without them being logged into Facebook?
I hope this helps,
http://graph.facebook.com/USERNAME OR USERID/picture?type=large
http://graph.facebook.com/USERNAME OR USERID/picture?type=small
http://graph.facebook.com/USERNAME OR USERID/picture?type=square
You do not need to log into facebook just use USERNAME OR USERID.
This is simple, basic thing and require only Googling...
If you're not looking for this, please elaborate the task you're doing...
Good Luck!!!
Simply use the following Graph path via GET request:
/{user_id}?fields=picture.type(large),id,name
Field type can be one of the following values:
small
normal
large
square
Or using width and/or height value like this:
/{user_id}?fields=picture.width(200).height(200),id,name
Also you can add redirect=0 param.
By default the picture edge will return a picture instead of a JSON response. If you want the picture edge to return JSON that describes the image set redirect=0 when you make the request.
So you will have the following JSON response:
{
"picture": {
"data": {
"height": 120,
"is_silhouette": false,
"url": "https://scontent.xx.fbcdn.net/hprofile-xaf1/v/t1.0-1/c53.10.120.120/165675_138088076251005_752993_n.jpg?oh=a9450bf53f2d2294531e11ae28be99c1&oe=56C740A5",
"width": 120
}
},
"id": "138087416251071",
"name": "Zenonis",
}

getting facebook comment by comment id

I am trying to get details of a comment by its comment id. This comments exists in a facebook comments box plugin which I have used in a website.
I tried the facebook api explorer and using this as the input
1388155601440738?fields=id,from,created_time
I got the response I wanted
{
"id": "1388155601440738",
"from": {
"name": "Ahmed Anas",
"id": "599062201"
},
"created_time": "2014-01-06T08:12:25+0000"
}
Unfortunately I cant figure out how to implement this in php..
I would assume all I need to do was get the contents from
http://graph.facebook.com/1388155601440738?fields=id,from,created_time
but I get an Unsupported get request exception
I also tried the php API with this code but no luck
$response = $facebook->api(1388155601440738);
$response = $facebook->api('/1388155601440738?fields=id,from,created_time');
I believe the comment id you are passing is incorrect. Also you have to add /comments after comment id. So the final URL for you would be something like http://graph.facebook.com/750281525001535/comments?fields=id,from,created_time. This one works fine

How to get user image with Twitter API 1.1?

In API 1.0, we can use users/profile_image/:screen_name
For example : http://api.twitter.com/1/users/profile_image/EA_FIFA_FRANCE
But, it doesn't work anymore in API 1.1.
Do you have a solution, please ?
You can also get the twitter profile image by calling this kind of url :
https://twitter.com/[screen_name]/profile_image?size=original
For instance : https://twitter.com/VancityReynolds/profile_image?size=original
Got the info from this post :
https://twittercommunity.com/t/how-to-get-user-image-original-size-with-api-1-1/10187/14
The user's profile image
Okay, so you want a user's profile image. You're going to need to take a look at the twitter REST API 1.1 docs. This is a list of all the different requests you can make to their API (don't worry, I'll get to how you actually do this later on).
There are multiple ways to get the user's profile image, but the most notable one is: users/show. According to the docs for this, the users/show method:
Returns a variety of information about the user specified by the required user_id or screen_name parameter. The author's most recent Tweet will be returned inline when possible.
Well, the user profile image must be in there somewhere, correct?
Let's have a look at a typical response to a request for this information, using the users/show url (we'll use my profile as an example).
I've cut off some from the bottom, because there is a lot of data to go through. Most importantly, you'll see what you require:
This is the profile_image_url key that you need to get access to.
So, how do you do all this? It's pretty simple, actually.
Authenticated Requests
As you rightly pointed out, as of June 11th 2013 you can't make unauthenticated requests, or any to the 1.0 API any more, because it has been retired. So OAuth is the way to make requests to the 1.1 API.
I wrote a stack overflow post with an aim to help all you guys make authenticated requests to the 1.1 API with little to no effort.
When you use it, you'll get back the response you see above. Follow the posts instructions, step-by-step, and you can get the library here (you only need to include one file in your project).
Basically, the previous post explains that you need to do the following:
Create a twitter developer account
Get yourself a set of unique keys from twitter (4 keys in total).
Set your application to have read/write access
Include TwitterApiExchange.php (the library)
Put your keys in a $settings array
Choose your URL and request method (Post/Get) from the docs (I put the link above!)
Make the request, that's it!
A practical example
I'm going to assume you followed the step-by-step instructions in the above post (containing pretty colour pictures). Here's the code you would use to get what you want.
// Require the library file, obviously
require_once('TwitterAPIExchange.php');
// Set up your settings with the keys you get from the dev site
$settings = array(
'oauth_access_token' => "YOUR_ACCESS_TOKEN",
'oauth_access_token_secret' => "YOUR_ACCESS_TOKEN_SECRET",
'consumer_key' => "YOUR_CONSUMER_KEY",
'consumer_secret' => "YOUR_CONSUMER_SECRET"
);
// Chooose the url you want from the docs, this is the users/show
$url = 'https://api.twitter.com/1.1/users/show.json';
// The request method, according to the docs, is GET, not POST
$requestMethod = 'GET';
// Set up your get string, we're using my screen name here
$getfield = '?screen_name=j7mbo';
// Create the object
$twitter = new TwitterAPIExchange($settings);
// Make the request and get the response into the $json variable
$json = $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
// It's json, so decode it into an array
$result = json_decode($json);
// Access the profile_image_url element in the array
echo $result->profile_image_url;
That's pretty much it! Very simple. There's also users/lookup which effectively does the same thing, but you can:
Returns fully-hydrated user objects for up to 100 users per request, as specified by comma-separated values passed to the user_id and/or screen_name parameters.
If you ever need to get more than one user's details, use that, but as you only require one user's details, use users/show as above.
I hope that cleared things up a bit!
You say you want to use Twitter API 1.1 and yet you don't want to authenticate your requests.
Unauthenticated requests are not supported in API v1.1. So please adjust to the API change. See updates :
https://dev.twitter.com/blog/planning-for-api-v1-retirement
https://dev.twitter.com/docs/rate-limiting/1.1
You can get image from profile_image_url field of https://api.twitter.com/1.1/users/show.json request. Either a id or screen_name is required for this method. For example :
GET https://api.twitter.com/1.1/users/show.json?screen_name=rsarver
See details here https://dev.twitter.com/docs/api/1.1/get/users/show
I try the above methods to get the profile URL but it does not work for me. I think because Twitter changes API v1.1 to API v2.0.
I found a simple method to get a profile URL.
I use Twitter API v2 there User Lookup -> User by Username API part
Code Sample:
https://api.twitter.com/2/users/by/username/{user_name}?user.fields=profile_image_url
For Example:
https://api.twitter.com/2/users/by/username/TwitterDev?user.fields=profile_image_url
Of course, You should request with your Bearer Token then it properly work. For that, I recommend a platform it calls postman. It really helps for calling API.
Above example code return JSON like this:
{
"data": {
"name": "Twitter Dev",
"profile_image_url": "https://pbs.twimg.com/profile_images/1445764922474827784/W2zEPN7U_normal.jpg",
"username": "TwitterDev",
"id": "2244994945"
}
}
Additional:
If You want the Profile Image to be a higher size. Then you can put size in place of normal in the URL. For More Details read this one
Like This:
https://pbs.twimg.com/profile_images/1445764922474827784/W2zEPN7U_400x400.jpg
Give a vote to help more developers. 🍵
As the previous answers and comments point out:
Twitter API v1.0 is deprecated
Twitter API v1.1 requires OAuth
OP (#Steffi) doesn't want to authenticate
Pick any two; with all three it's a no-go. #Jimbo's answer is correct (and the proper way to do it), but excludes #3. Throwing out #1 means going back in time. But, we can throw out #2, and go directly to the source:
curl -s https://twitter.com/EA_FIFA_FRANCE |
sed -ne 's/^.*ProfileAvatar-image.*\(https:[^"]*\).*$/\1/p'
The sed command just says, find the line that contains "ProfileAvatar-image" and print the substring that looks like a quoted URL.
This is less stable than an authenticated API call, since Twitter may change their HTML at any time, but it's easier than dealing with OAuth, and no official rate limits!
The PHP translation should be straightforward.
try this
http://api.twitter.com/1/users/profile_image/{twitter_account}.xml?size=bigger
In API 1.1 the only way is to connect your application, retrieve the user by
https://dev.twitter.com/docs/api/1.1/get/users/show
and retrieve after his picture
profile_image_url
Hare is a very simple way to get Twitter Profile picture.
http://res.cloudinary.com/demo/image/twitter_name/w_300/{User_Name}.jpg
it's my Profile picutre:
Big: http://res.cloudinary.com/demo/image/twitter_name/w_300/avto_key.jpg
Small: http://res.cloudinary.com/demo/image/twitter_name/w_100/avto_key.jpg
you can regulate size by this part of URL - w_100, w_200, w_500 and etc.

Categories