I am working in mobile environments that do not support Javascript. Is it possible to add Facebook Like functionality to a page, probably doing server-side requests to Facebook?
For a more detailed example, if I go to http://ogp.me/, there is a Like button towards the bottom of the page. Clicking on that uses Javascript, optionally signing into Facebook if the relevant cookies aren't there.
I want to provide the same functionality, but without using Javascript (clue: need to support Blackberry browsers).
My intention was to use OAuth 2.0 with standard redirects, to get an access token with which to call the Graph API.
Once I have an access token, I was expecting something like
curl https://graph.facebook.com/me/likes?access_token={a-valid-access-token}&category=Website&url={url-encoding-of-url-to-like}
where the access token has the publish_stream permission granted to it. So to be more explicit:
curl https://graph.facebook.com/me/likes?access_token={a-valid-access-token}&category=Website&url=http%3A%2F%2Fogp.me%2F
That attempt returns me a 403 response, and I've not found anything else in the fine manual
The graph api does allow you to like a graph object (see Graph API Docs / Publishing) using:
https://graph.facebook.com/OBJECT_ID/likes
However the graph object must have an existing likes connection - and there's currently no way of creating such a connection via the graph api.
But if the like connection already exists you can get the pages graph object id using FQL:
SELECT id FROM object_url WHERE url='http://youtargeturl.lnk'
Related
My previous implementation of using GET request to url https://graph.facebook.com/538726722826117 is broken now that Facebook has moved to Graph API v2 and requires an auth token for fetching this information. And as it is a website, I cannot embed a token which would have any more access rights than for reading a page's public information.
How to implement this rather simple task of getting a page's public like and check-ins count?
You don´t need to autorize, you can just use an App Access Token for the API call. Of course you should not use the Token on the client, but it´s perfectly fine to use it on the server. Make the API call with file_get_contents or curl - that is, if you are using PHP.
An App Access Token is very simple, it´s just the App ID and the App Secret, combined with a pipe sign: App-ID|App-Secret
More information about Tokens for the Facebook API:
https://developers.facebook.com/docs/facebook-login/access-tokens
http://www.devils-heaven.com/facebook-access-tokens/
Is it possible to use facebook-api without making any facebook app, just from Graph api?
So that I can ask people to share there facebook profile information(public or non-public) with me given that they have control over whatever information they want to share. In graph-api, the only way I know, is to ask people to get a access token and give me.
I wanted it to be a system generated request for permission and all they had to do is just hit okay or hit cancel and depending that I get response related to access-token.
and To make a working facebook-app I atleast need to have a website or android app or something else, which I don't have it yet.
I can't think of any working way.
No, you need Access Tokens for almost all API calls, and you can only get Access Tokens with an App - no matter which Access Token.
#luschn is right that you need Access Token to API Calls. You can easily create a new app using Facebook. Once you created an app, you can generate token, which can be used to make Graph API Calls.
Helpful Links:
App Create Link https://developers.facebook.com/apps
Get Token: https://developers.facebook.com/tools/explorer?method=GET&path=comment&version=v2.11
Using app access token had previously been asked in this question (How to use Facebook appAccessToken with Spring Social) and Craig Walls gave a good explanation why the spring-social API should be user-based for most cases.
I have a scenario, however where I would like our server-side application to make a couple of queries that should not require user-specific permissions. I picked a random public page for examples below
I would like to:
View details about a public page by alias/id
https://graph.facebook.com/v2.0/121727254549188
https://graph.facebook.com/v2.0/peterstevensmotorcycles
View posts for a public page by alias/id
https://graph.facebook.com/v2.0/121727254549188/posts
https://graph.facebook.com/v2.0/peterstevensmotorcycles/posts
Search for pages
https://graph.facebook.com/v2.0/search?q=Peter%20Stevens%20Motorcycles&type=page
When I test these in the Graph API explorer (https://developers.facebook.com/tools/explorer) using an App Access Token they work fine. App Access Token is obtained by hitting https://graph.facebook.com/v2.0/oauth/access_token?client_id={app-id}&client_secret={app-secret}&grant_type=client_credentials and replacing client_id and client_secret with my Facebook client credentials.
Our application would like to have the ability to make these for any given name so we can make queries about a company's presence.
We will have similar requirements for Twitter, LinkedIn and others so I just wanted to check if there are any means to do this in the current API or whether it will not suit our requirements.
You do not need to fetch an app access token - you can actually use the app id and secret separated by "|" as the access token. - You can see it at the bottom of the app access token section in the documentation: https://developers.facebook.com/docs/facebook-login/access-tokens#apptokens
Spring Social's Facebook API binding does not (yet) support v2.0, but that's something I'm working on right now...so hopefully soon. Once that's complete, there'll certainly be some operations that work only with user access tokens and some that only work with app access tokens, and some that will work with either (FWIW, Twitter's API has a similar set of circumstances).
Keep an eye on the project in GitHub or follow #SpringSocial on Twitter to know when the v2.0 stuff is available. (I'd appreciate any help I can get in testing it.)
Although it makes no sense at all to obtain your FacebookTemplate via the connection framework for app token requests (connections are, by nature, a user-oriented concept), you can always construct a FacebookTemplate wherever you need it, giving it an app access token obtained via OAuth2Template's authenticateClient(). You can certainly do that now with the v1.0 API binding, but I'm uncertain what ops an app token would work with.
FWIW, as I'm working on the v2.0 API binding, I'm starting to sense an opportunity for FacebookTemplate to carry two tokens: A user token and an app token. This way you can perform app-centric requests even from a FacebookTemplate obtained from the connection framework. Then the only time you'd ever want to construct a FacebookTemplate manually is if there are some operations for which either kind of token will work, but the results would be different depending on what type of token is used.
I'm trying to use the new graph api for using FQL (the old api used https://api.facebook.com/method/fql.query?query=select%20like_count,%20comment_count,%20share_count,%20click_count%20from%20link_stat%20where%20url=%22facebook.com%22),
but it looks like I need an access token to use the new api ( http://developers.facebook.com/docs/reference/rest/links.getStats/).
Is there a way to get statistics on a link without having a user logging in (a functionality like the old api)? Can this be done using only a Facebook appId?
Thanks.
Just call this url and parse the json response (obviously replacing the google.com with your page):
http://graph.facebook.com/?id=http://google.com
This url doesn't not require any kind of access token.
I feel like every second question i ask here is relating to Facebook Connect - that says a lot about their API. Anyway, that's politics, i digress..
I'm trying to pull back user details from the Graph API for use in my application (which is an FBML external website - JavaScript SDK for authentication).
I have requested the following permissions from the user: (using the regular dialog)
publish_stream
email
This works, and allows me to post to the user's wall, and grab their email from the Graph API.
But when i do a HTTP GET Request to the following URL:
https://graph.facebook.com/uid?access_token=oat (where uid = the user id of the user i'm attempting to grab details for, and oat = the OAuth token i have).
All that comes back in the JSON is the User ID (which i already have, since im putting it in the URL), and the email.
Why can i not get things like first name, last name, locale, etc?
Am i using the wrong URL? Is my OAuth token wrong?
I'm getting the OAuth token from here:
https://graph.facebook.com/oauth/access_token?type=client_cred&client_id=myappid&client_secret=myappsecret
UPDATE:
It looks like the issue is my OAuth token.
Because when i go to the docs: http://developers.facebook.com/docs/api
And use the sample OAuth Token for the user im trying to retrieve, it gets all the details.
Anyone know what is wrong with my OAuth token call?
So, i was using the wrong URL for the OAuth Exchange. It needed to be this:
https://graph.facebook.com/oauth/exchange_sessions?type=client_cred&client_id=myappid&client_secrete=myappsecret&sessions=userseshid
The URL that i WAS using was as per the doco, the above one that works is nowhere to be found.
I'm at the point with FBC that i no longer care about the how, if it works, be thankful that it does even that and move on.
EDIT:
Also, i was wondering why the Graph API calls would "stop" working for no reason.
The answer is i needed to compare the Session Key used to obtain the OAuth token, with the Session Key currently in the cookies. If they are different, i needed to get a new OAuth token.
The session key used for any OAuth token is part of the actual OAuth token:
aaa|bbbb|cccc
Where bbbb is the session key. So i just compare that before doing any Graph API calls.