I have successfull requested an access_token through manual login system construction. Please keep in mind I'm not using facebook php login API or javascript SDK. In the access token I asked permission to obtain the public profile and user_friends who also use my app. I have obtained public information using file_get_contents("https://graph.facebook.com/me?$access_token"); and I got the profile link, the name, the gender, etc, but how can I obtain the user_friends as mentioned above and how exactly do I manage context with the access token to obtain those informations? I don't understand how to use context with the file_get_contents above too...
Related
Good morning all,
I must create a site in PHP where we enter the url of the facebook profile, and then it must retrieve some information from the profile:
The profile picture
The name
If the profile and verify
I wish I could do it without this connection.
What to give me a clue?
(I succeeded with tiktok, instagram, etc.) but with facebook it's been a while that I'm looking for the solution
This is not possible for 2 reasons:
Scraping is not allowed on Facebook, you must use the API for accessing any data
Any user data is unavailable with the API, unless the user authorizes your App to access his data
The correct way to implement verification is to implement login with the Graph API and let the user authorize your App. Btw, this still does not mean you can verify his profile url, because you will not get the real URL, not even with authorization.
I've been trying to get Google's Calendar API working in a PHP web application, but I'm having a hard time getting authenticated.
What I want to do is to allow users to interact with calendars of a single account known by the server.
Each type of scenario covered in the OAuth 2.0 docs talks about "user consent" which involves a login form and the individual user logging in, but I want the server itself to authenticate directly and obtain an access token for itself.
Is there some part of OAuth or some alternative mechanism I can use to do this?
In order to do this, you must go through the steps for user consent and then copy the access tokens it gives you into the PHP code.
The usual procedure for OAuth is like this:
Send user to authentication page.
User comes back with $_GET['code']
Send $_GET['code'] to OAuth server for a token
Store token in database for the user (or session, if it's very short lived)
But when doing it with a single calendar like this, you modify step 4. Instead, you dump the token to screen and copy it into your PHP file as variables, instead of putting it in the database. Then when you go to pass the access token to the server, you just pass the known, static token rather than a dynamic token from the database / session.
See mathewh's answer here:
How to automate login to Google API to get OAuth 2.0 token to access known user account
The lightbulb for me is when you get the access token you get a refresh_token as well... you use this token to "refresh" your access token once it expires.
There is no way around a manual authorization step the first time.
i'm trying to get user's public information (name, photo, gender, profile link).
as i seen in https://developers.facebook.com/docs/reference/api/user/ to get this information i don't need any access token.
i'm using the facebook.php sdk to connect to facebook as written in the example:
https://github.com/facebook/php-sdk/blob/master/examples/example.php
for some reason it always ask me to get access token for basic information, although all i need is public information...
how can i get the public information only with no access token ?
To get public information without an access token, just go to the graph itself.
Try https://graph.facebook.com/4 for an example.
To get the information from the user, the user has to grant you their information. This is done by them logging in to your site via their facebook account. By implementing the Facebook PHP SDK on your site you can use the function getLoginUrl() to provide the login url to the users. When they've logged in, they'll be sent back to your site with their id available. You can then use the api() method to query the graph for the information you want. Remember that for all information that is not public, you'll need to ask for privileges when they connect their account.
If you don't have their access token, you can't get information from them. You'll need to know who the users are in order to query for information. But once you've got their access token you can store basic information in your own database so that you don't have to query the graph next time.
According to the instruction given here searching public information (as https://graph.facebook.com/search?q=QUERY&type=OBJECT_TYPE) needs to have a valid access token. As I know access token is when a user authorized an apps to access his information; but this is searing the public information. How to get an apps access token to search public information?
In that page, facebook automatically add my access token to the link as
https://graph.facebook.com/search?q=watermelon&type=post&access_token=MY_ACCESS_TOKEN
I created an access token by my apps as https://graph.facebook.com/oauth/access_token?client_id=APP_ID&client_secret=SECRET_ID&grant_type=client_credentials
When I use the generated access token in url https://graph.facebook.com/search?q=watermelon&type=post&access_token=GENERATED_ACCESS_TOKEN, it gives an error
{
"error": {
"message": "A user access token is required to request this resource.",
"type": "OAuthException"
}
}
How can I generate access token by my apps?
Or do I need to generate access token by own user account? if yes, how?
Since it is searching public profile, facebook should not need authorization on every search, can I generate a permanent access token to perform different searches?
The Graph API Search interface has changes pending with the Q3 2013 migration.
The following change will go into effect on July 10, 2013:
Graph API search changes
App access tokens will be required for all search Graph API calls except Places and Pages. Search for application will no longer be supported.
https://developers.facebook.com/blog/post/2013/04/03/platform-updates--operation-developer-love/
For searching the facebook graph API using
http://graph.facebook.com/search?q=watermelon&type=post
you need a valid user access token. A user access token is different from App Access token. A user access token is created when a user authenticates your app with different access permissions which is generally close to 212 letters long.
A changes was made in the graph API in July,2013 whereby you will need to have a valid user access token to search for users and posts. The user access token could be generated by you yourself authenticating your app and generating an user access token for your app.
But the question remains, How should we generate a user app token for our apps without making other users to authenticate our apps?
The access token you are requesting looks like an 'application' access token. This token differs from a 'user' or 'page' access token and is used for different things.
https://developers.facebook.com/docs/howtos/login/login-as-app/
This can be used to modify the parameters of your App, create and
manage test users, or read your application's insights for example.
App access tokens can also be used to publish content to Facebook on
behalf of a person who has granted a publishing permission to your
application.
Depending on what you are trying to actually do, an application token might be the wrong form of OAuth. Your example (searching for public posts with the term watermelon) doesn't require an OAuth token, so you're obviously trying a different type of graph search. Without saying what you're actually trying to access, it's impossible to actually advise you correctly.
However, I'm going to guess that you're trying to get access to graph objects that require permissions from a specific user. If that's the case, then you need to get permissions from that user first, by requesting the scope of permissions that you require.
Process of gaining user OAuth Access Token (https://developers.facebook.com/docs/reference/dialogs/oauth/)
Possible Permissions (scope) that can be requested (https://developers.facebook.com/docs/reference/login/)
This will give you a short term access token for that user, which will allow you to anything within the scope of permissions for which you've requested permission.
This token will only last for a short period after the user has logged into your app. It can also be promoted to a longer term access token
https://developers.facebook.com/docs/howtos/login/extending-tokens/
You don't need to pass any token to search in public information (unless you want to search in user's context). Just make a call to the following url and see the URL. Please mark that I have used http instead of https.
http://graph.facebook.com/search?q=watermelon&type=post
But to make my answer more clear - with properly granted access_token I can make a call to the https version of the above url (https version requires an access token) and it just works fine without any problem.
If you are searching programatically and the search URL will never be visible to the end user you can use this instead:
&access_token=app_id|app_secret
More about this here: https://developers.facebook.com/docs/facebook-login/access-tokens/
I am trying to get FB user's full name using the access_token. I have the access_token with me but I am not sure how I can use it to access user information.
I have read the documentation and it says to get more user info we can use:
https://graph.facebook.com/userid?access_token=...
So, does this mean I need to use cURL to get response from this URL?
Btw, I am using PHP.
Thanks.
Accesstoken you can use for getting the information of the user which is necessary. Also if you have asked offline_access permission from user, you can store this accesstoken in your database and can get the user information even if he not logged in with facebook. That means, from next time you automtically get the information using this token.