Linkedin API get public-profile - rest

I am trying to get the id from the public-profile-url. The query looks like:
https://api.linkedin.com/v1/people/url={https://www.linkedin.com/in/name}
However, what I get get back from linkedin is:
<error>
<status>400</status>
<timestamp>1460131755319</timestamp>
<request-id>2OV9FJ0DTR</request-id>
<error-code>0</error-code>
<message>[invalid.param.url]. Public profile URL is not correct,
{url=}; should be {https://www.linkedin.com/pub/[member-name/]x/y/z} or
{https://www.linkedin.com/in/string}</message>
The interesting part is:
Public profile URL is not correct, {url=}; should be {https://www.linkedin.com/pub/[member-name/]x/y/z} or {https://www.linkedin.com/in/string}
The url clearly adheres to the rules that they mention and the url works. Any idea on how to fix it?

You cannot reliably retrieve a member ID from a profile URL. id values that you can rely on are returned as part of Profile API calls. From time to time, LinkedIn changes the format of it's public profile URLs, so attempting to parse them or reconstruct them can leave your app in a broken state. The public-profile-url field should be considered read-only, and not something you try and parse or create yourself.
e.g.: GET https://api.linkedin.com/v1/people/~:(id,first-name,last-name,public-profile-url)?format=json
id values are encoded to specific LinkedIn applications and cannot be re-used between apps. As a result, any value you attempt to pull out of a URL won't be of any use to you. The information needs to be acquired via an API call.

Related

How to pass user id

Suppose super admin wants to see another sub admin's details
my current method is GET -- domain/api/user/get_by_id/{id}
I'm using JWT also.
is my method correct?? Is there any other method where I don't put the id directly in URL
my current method is GET -- domain/api/user/get_by_id/{id}
So, answering your questions one by one,
is my method correct??
If you are using RESt Web services as you have added that tag, then no, this should not be the url. I would suggest you to read upon REST web services a little as the url should look somewhat like this.
GET -- domain/api/user/{id}
Also the id you put in url is a public one and not the one of your database. So a entry in the database should look like:
Id | Username | userId (it is public)
1 | debabrata| r1398fh9238yhas89
So to call the url r1398fh9238yhas89 will be passed and not 1.
Is there any other method where I don't put the id directly in URL
You could encode the id in base64, jwt style or some kind of other encryption or as earlier stated just send a public ID which doesn't mean anything for your database.

Facebook graph api - Unsupported get request

I'm creating a custom module in Drupal, that for part of its functionality must fetch posts from a business page. So for simplicity, I'm using fbapp module as a dependency (drupal.org/project/fbapp), so that I can use it's authentication and request functions (fbapp_app_authenticate() and fbapp_graph_request()) without having to worry about the constant facebook graph updates making my own code obsolete.
I've created a facebook app, so authentication should be app token, using appid and app secret. This seems fine and I'm getting back access_token. However, when I try to read posts from a publicly available page (the clients), I get the response:
"Unsupported get request. Please read the Graph API documentation at https:\/\/developers.facebook.com\/docs\/graph-api"
Here's the queries and responses my code produces:
graph.facebook.com/oauth/access_token?client_id=<redacted>&client_secret=<redacted>&grant_type=client_credentials
array(1) {
["access_token"]=>
string(43) "<redacted>|<redacted>"
}
graph.facebook.com/<page_id>/posts?access_token=<redacted>|<redacted>"
string(183) "{"error":{"message":"Unsupported get request. Please read the Graph API documentation at https:\/\/developers.facebook.com\/docs\/graph-api","type":"GraphMethodException","code":100}}"
Can anyone verify a correct way to query a Facebook page programmatically, perhaps there's a setting in the page I'm querying that I need to set (although I can't find anything)?
If page restrictions apply, the page's feed can only be retrieved with an user access token as far as I know (because FB needs to evaluate the visibility criteria, and setting your app to the same restrictions doesn't help here):
See
https://developers.facebook.com/docs/graph-api/reference/v2.4/page/feed#readperms
It looks like everything you have done is correct. The response you got can be (i am not sure) because you got your clients pageid wrong.

Understanding Facebook Graph API identifiers

While I do realize that the ids for graph api objects are not documented, I'm seeing some oddities which I'd like to understand.
I have an authorized app that polls a page's feed for new comments and it looks like I'm getting different ids for the same post.
On first run I get a post with the id of:
1470990656482896_1553567768225184
Which is the id of the page and post joined by an underscore.
The second poll which ran a few minutes later, I received the same post with a different id:
100008124617959_1553567768225184
Which is the user id of the poster and post joined by an underscore.
While I'd like to understand the inconsistency, the real problem is trying to access the post via the second identifier returns an Unsupported get request with the code of 100
The post is public and is accessible via both
https://www.facebook.com/100008124617959/posts/1553567768225184
and
https://www.facebook.com/1470990656482896/posts/1553567768225184
This sounds like an oauth problem. While the post is public, to access it via the graph API you have to use an access token.
If you use the access token for Hans Gotwo then you should be able to access the post with the id of 100008124617959_1553567768225184
Looks like it's a bug. thanks #phwd
https://developers.facebook.com/bugs/721538487964698/

Facebook Graph API: Find graph object from post URL

Given the URL of a public Facebook post, how can one find the post object in the FB Graph API? (secondarily, why are so many user feeds empty or nearly empty when accessed through the API?)
We would like to be able to comment on or like a post via the v2.x
Graph API, given the post's URL. Doing so requires the post's object
ID, which we can make some educated guesses about, but accessing
the actual object through the API has proven unreliable (works for some posts but
not others).
v2 of the API introduced app-scoped user IDs, and post IDs generally seem
to be of the form {app-scoped user id}_{unique post id}. Here are the
details of some attempts to find posts in the API with various combinations of
these IDs (global user id, app-scoped user id, and post id).
Starting with a simple example: https://www.facebook.com/evan.prodromou/posts/10153023417510505. Key characteristics are that it's public, it's not a share of another post, and most importantly it has no photo(s), which add extra ids and URLs for the individual photo(s) and photo set. Evan's profile is also public, i.e. https://www.facebook.com/evan.prodromou doesn't show the generic This content is currently unavailable
Trying the bare post id from that URL, /v1.0/10153023417510505 and /v2.2/10153023417510505 both give the Unsupported get request (code 100) error.
Evan's global user id is 525575504. Attaching that as a prefix, /v1.0/525575504_10153023417510505 and /v2.2/525575504_10153023417510505 still both give the same Unsupported get request error.
Same error using his app-scoped user id instead, /v2.2/10152350676805505_10153023417510505.
OK let's try the other direction. We'll page through the user's feed until we find the post in question. It feels like this is more the expected use case for the API...
Both the global /v2.2/525575504/posts and app-scoped /v2.2/10152350676805505/posts return nothing, but /v1.0/525575504/posts returns two recent posts, this like and this post. Not sure why only those two, even though has plenty of other recent public posts. The like is fetchable via its id field in both api versions, i.e. /v1.0/525575504_10153045879215505 and /v2.2/10152350676805505_10153045879215505, but both API versions return the Unsupported get request error when fetching the post via its id field, e.g. /v1.0/525575504_351575675029953 and /v2.2/10152350676805505_351575675029953
Trying another public post, this one with pictures: https://www.facebook.com/andigalpern/posts/678121182314631 . /v1.0/100003502653187_678121182314631, /v2.2/100003502653187_678121182314631, and /v2.2/499657186827699_678121182314631 all error.
/v1.0/100003502653187/posts only includes one post, a like, and /v2.2/100003502653187/posts is empty.
For reference, here is the GitHub issue where we have been tracking this problem.
Basically you would need read_stream for this (which your app will not get granted). And yes, even though the post is public, you still need read_stream to be able to get read access to all kinds of posts.
You can easily play around with this in Graph API Explorer. First give your app read_stream permission to get ids of items in your feed – that will give you ids of the “form app-scoped user id underscore post id”. Then remove read_stream (by clicking “Get Access Token” again and using the “Clear” button), and try several of the user_* permissions – and you will see that for most of your posts, even the public ones, you will still only get “Unsupported get request”, which just means you are not allowed to read that object.
F.e., I have a public post where shared a video post from another page on my timeline, the type is video and status_type is shared_story, but neither user_status nor user_videos allow me to read this post – only when I grant read_stream again, my app can read that post. Same with another public post of type status and status_type mobile_status_update – readable with read_stream, not with any of the user_* permissions.
In short: What you want to achieve is not possible any more with API v2 and the restriction that read_stream will only be granted to apps on platforms where no official FB client exists.
A one proposition is to make api calls to write facebook posts since those return valid post_id that you could use
Second,
When you try https://developers.facebook.com/tools/explorer/256884317673197/?method=GET&path=525575504%2Fposts&version=v2.0&
You can see that his posts ID's are not starting with his public id as you wrote 525575504_*
but they still put unsupported get request
https://developers.facebook.com/tools/explorer/256884317673197/?method=GET&path=10152853212485505_351575675029953&version=v2.0
Third since above doesnt work are those posts public for sure?

Retrieving the action-instance-id from Facebook given the URL

tl;dr: No, there isn't a way.
Calling publish_action using the JS SDK is actually pretty straightforward. However (from the little info I gleaned from reading the documentation), there's no way for me to query facebook to have it return the action instance ID for an object that I have already published... is there?
Example:
User A loads the page, and the page sends an FB.api call to /me/news.reads, which returns an action instance ID.
User A reloads the page, and the page again sends an FB.api call to /me/news.reads, but this time, the Graph API returns:
{
error: {
code: 3501,
message: 'blahblahblah... already associated... blah blah'
type: 'OAuthException'
}
}
Pretty standard stuff, and expected, since I turned off the ability to publish the same URL multiple times.
Now then, is there any way for me to retrieve a previously published action instance ID from the Graph API by passing in the URL, or is it up to me to handle the returned action instance ID (from the original publication attempt) and save it to a database? I was hoping I wouldn't have to do that...
No, there is no way to retrieve instances of published actions other than:
Accessing action by id:
http://graph.facebook.com/ACTION_ID
Accessing all instances published by specific user:
http://graph.facebook.com/USER_ID/NAMESPACE:ACTION (NAMESPACE:ACTION may be replaces by the name of one of built-in actions like news.reads, music.listend, etc.
If you want to access details of published actions connected/referencing specific object you'll need to save that data on your end for later usage.