How can I find an URL of a Facebook page from its ID? - facebook

I know a Facebook page ID and I’d like to get a full URL to the page. The full URL looks like this:
http://www.facebook.com/pages/page-title/numeric-id
I don’t know the page-title. If I drop it from the URL and just use the numeric ID, I get a 404. I can call the Graph API to get the full URL from the ID, but that’s too heavy (one extra HTTP request, JSON parsing). Is there a better way?

I'm not fimiliar with Facebook Application but I know a bit about it. If you're talking about the page title, then there is a "name" object in your response code. Get that, and replace the white space with - and place your ID. May be, It will work
'http://www.facebook.com/pages/'.str_replace(' ','-',$name).'/numeric-id
// $name is your page name fetched from object.

Related

REST: nested resource url when you don't want the parent ID visible

I read that the route for getting a nested resource in REST should look like this
/articles/:articleId/comments
The owner (:articleId) of the child resource will be visible.
But what if you have an owner that you don't want the client to know about?
For example, let's say I have an app where users have anonymous posts. I wouldn't want other users to see the client fetching the post by /users/123/post/321 because users could identify who wrote the post from the id and it wouldn't be anonymous.
Is the id necessary? Is it ok to instead do /users/posts/321 if all posts have a unique id?
There are no actual requirements for the URL format. It can be whatever you'd like it to be.
If it were me, I would use simply /posts/321 and leave users out of it, since a particular user isn't specified in your URL at all. I think that's the clearest way to handle it in your case.

Linkedin API get public-profile

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.

Convert any facebook URL into a graph ID

Is there a simple, reliable and potentially future-proof way to extract a graph ID from the API given any facebook URL? By "any facebook URL" I mean the URL for a personal profile, page, group, etc. All these things have various formats so I imagine there must be something in the graph API to definitively convert a facebook URL into an ID, right?
No, there isn't a way to do this simply within the API. You will need a set of pattern matching to match the various types of urls to extract either the id (album,note,photo,status) or username.
For example
Photos
facebook.com/photo.php?fbid=10100213582161431&set=p.10100213582161431&type=1&theater
https://graph.facebook.com/10100213582161431
Posts
facebook.com/zuck/posts/10100210345757211
https://graph.facebook.com/10100210345757211
Pages
facebook.com/pages/Joel-Spolsky/106083232757300
graph.facebook.com/106083232757300
Videos
facebook.com/video/video.php?v=10150398154330484
graph.facebook.com/0150398154330484
Events
facebook.com/events/138745136241434/
etc ...
Then it gets further complicated that even if you were able to get a silver bullet function that handles all these links your app would need to grant access to numerous permissions in order to access certain objects.
You may be able to get away with most links that have the id at the end but not all. So you can maybe use a regular expression catching links that end in numeric characters.
There is! You are looking for the object_url table, which you can query using FQL or directly with a request. See here: http://developers.facebook.com/docs/reference/fql/object_url/
EDIT:
You can also do this, but obviously less optimal:
function getObjectByUrl(url, cb) {
FB.api("/" + url.replace(/^.*?www.facebook.com/, ""), cb);
}

What are the "base URLs" for status, photos, etc?

I developed an app that looks for specific terms using the facebook api (search).
Every result comes with an ID for the item that can be of many types like "status","photos",etc.
I remember that some time ago I could surf facebook and get this URLs from the browser address bar, but now with some updates that facebook has made it seems to be all AJAX based calls and it seems like you do not have a "specific page" for each item.
I looked over the web and could not find anything regarding this.
Is there any way I can get a "photo id" from the API and open it like "http://facebook.com/photos/0293820293842"?
Thanks for any clue.
https://graph.facebook.com/{id}/picture
https://graph.facebook.com/40796308305/picture (by page id)
https://graph.facebook.com/cocacola/picture (by page's name)
https://graph.facebook.com/4/picture (by user id)
https://graph.facebook.com/4/zuck (by user name)
after some time I just gave up trying to get the picture from the data provided by the search API.
From the api I get entries of type "photo" but they do not match with the API documentation found at http://developers.facebook.com/docs/reference/api/photo/ since I do not receive the fields "picture", "source" or "images" (they just does not exist in the results from a search)
Looking to find a way to use the approach of "setting up the URL from the fields received from the API" I could not get any sucess either.
That's one case... I set up a search for "pepsi"... and within the results I got a "photo" object.
In this object I have the following fields:
id: 100002307882828_188072634633218
author\id: 100002307882828
link : "http://www.facebook.com/photo.php?fbid=320417371337648&set=a.133681116677942.17717.131381520241235&type=1" (this link really points to the photo's page, but is not the photo itself)
object_id: 320417371337648
I used the URL you provided as a "base" and tried to setup some combination that returns me a photo but I always get "Content not found" as result.
The only way I could find the final photo URL is to make another call to the API using the Photo Id as parameter (but I would need to do a lot of calls to the API and this just do not fit my scenario)
If I call https://graph.facebook.com/320417371337648 I get everything I need from the photo, but this is the "another call" I would need to perform for each result I get.
Thanks a lot for your help,
Regards,
Victor Reboucas

on facebook connect login uri, can I add an extra get param on url, and have that passed to my script once user logs in?

to connect to an app on facebook, the user types in
www.facebook.com/login.php?api=12312312323123123
how can I add an extra get var to this url and pass it to my script on successful login?
Do you add a redirect_url as part of the login call?
If so you can add the GET parameter to that. For instance let us say you are asking Facebook to redirect to http://tld/fbhandler after user logs in. You can change that to http://tld/fbhandler?extra=value.
This URL is specified at the time of making the (OAuth) login call to Facebook and therefore you can change the value as you see fit.
You cannot do this. Facebook will strip custom query values from the url. I have found that there are two ways to do this. The first is that they will let you have a single query value at the end of the url if you encode the ? to %3F. For example:
redirect_url=http://www.example.com%3FmyextraParameter
You could use this approach to do something like base64url encode your values and add them at the end.
The other thing that I have done is to change the parameters to be path variables
redirect_url=http://www.example.com/realUrl/parameter1/parameter2
Neither are great solutions, but I have yet to find a way to send querystring values without them being stripped off.