Facebook marketing api acess token - facebook-graph-api

I am trying to get my ( OWN ) ad accounts data using facebook insights api. the very first step is getting access token. until now i was using access token generated by graph api explorer by extending it lifetime manually. now what is the programmatic way of getting access token. i have referred this documntation https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow/
This is only possible when i am using some sort of front-end or browser interface to open up login dialog but i am using a python script. its not possible to open up the login dialog. ho do i get my access token .
as far as i understand login dialog popu up when using user access token. i think i need to use app access token . are both same?

Follow the step here:
https://developers.facebook.com/docs/facebook-login/access-tokens/#apptokens
You can get the access token through the sample code
But reminded that because this request uses your app secret, it must never be made in client-side code or in an app binary that could be decompiled.

Related

The way to access reporting API v2.0 has changed (Facebook Graph-API)

My team and I have been trying to connect to the Graph-API (Facebook) for a few days to get access to Audience Network data through our API.
Steps we follow:
Implementation of Facebook Login flow
Generation of Access Token from the Facebook Login Button in our application.
Modification of the Access Token to a Long-Term Token.
We debugged both tokens through the official tool and it is possible to observe that it is a valid token with the proper access: https://developers.facebook.com/tools/debug/accesstoken/
In the settings, the JavaScript SDK is already properly activated
The request we are using as an example is:
https://graph.facebook.com/<API_VERSION>/<BUSINESS_ID|PROPERTY_ID|APP_ID>/adnetworkanalytics/?metrics=['fb_ad_network_imp']&access_token=<ACCESS_TOKEN>
We use the following documentation as reference and tools:
https://developers.facebook.com/docs/audience-network/optimization/report-api/guide-v2?locale=en_US
https://developers.facebook.com/docs/audience-network/optimization/apis/FB-login-Reporting-API
https://developers.facebook.com/docs/facebook-login/guides/access-tokens/get-long-lived
Even after all these steps, when trying to make a request to the Graph-API, through the explorer https://developers.facebook.com/tools/explorer/, we still receive the following message:
"The way to access reporting API v2.0 has changed. You now need to implement Facebook Login for your app to access this API. See instructions here: https://developers.facebook.com/docs/facebook-login/"
Is anyone trying to implement this flow or know how to fix this behavior?

Sending email (Office 365) using postman without logging in from browser

I would like to send an email on behalf of a user using Postman (Office 365). I have the email id and password of that account. After doing some research, I have found that I need to login, using a browser, to get the authorization code and then I can perform the next steps from Postman (getting the access token and using the Microsoft Graph Explorer) to send the email.
I would like to get the authorization code using Postman (not browser). I tried and got the following error (which is what should come the way I have requested the API)-
In short, I want to send email from Graph API using a REST client like Postman (right from authorization to sending email). Is this possible?
(I have already read these documents but did not help me get there-
https://developer.microsoft.com/en-us/graph/docs/concepts/rest
Accessing Microsoft Graph API without using login page
Automatically Log-In To Office 365
)
Yes, it is very possible, in fact, you can use all of the Microsoft Graph API from Postman or any other program which can make HTTP requests.
All you need to do is to get access token to use in your requests to the Graph API, and there at least 4 ways which allow you to do so without user interaction. But the process requires some preparation since you need to create an OAuth App in order to be able to use the Graph API.
Since I had to do the same myself and it wasn't easy to collect all the bits of information necessary, I've written a full guide on this subject including Postman examples:
Getting Access Token for Microsoft Graph Using OAuth REST API
In large you need to do the following steps:
Register OAuth App
Configuring App Permission
Use one of the following flows, depending on the information you have:
Flow 1: Get Access Token from Client Credentials (Client credentials Grant)
Flow 2 – Get Access Token From Client & User Credentials (Resource Owner Credentials Grant)
Flow 3 – Get Access Token From Refresh Token (Refresh Token Grant)
Flow 4 – Get Access Token From Another Access Token (On-Behalf-Of Grant)
Use the access token in requests to Microsoft Graph API
All of those steps are explained in the article.

Facebook ads api workflow

My app got white-listed for using the Ads API.
I was wondering in regarding to the authentication flow.
Say, that I need to retrieve and execute actions via the API on daily tasks ( with no user interaction) , I find the authentication process quite cumbersome.
Is there a way to work with my app access token instead of a user access token?
I want to be able to approve my app only once for each user and then to be able to work with no user interaction.
Can I achieve this?
App access token is not relevant for this case.
I had to work with the user access token.
I followed this doc: https://developers.facebook.com/docs/reference/ads-api/
Eventually , one should use some client side code in order to get a user permissions and then make another request for getting the user token.
So you'll have to call
https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_URL&scope=ads_management,offline_access&response_type=code
Get the authentication code and make another call:
https://graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID&redirect_uri=YOUR_URL&client_secret=YOUR_APP_SECRET&code=AUTHORIZATION_CODE
Then you'll get an access token which is valid only for two months, in opposed to what Facebook docs says in here:
https://developers.facebook.com/roadmap/offline-access-removal/
"Ads APIs are special cased to allow collection of statistics offline. PMD partners should use server-side OAuth flow in order to receive a non-expiring token rather than a token that has longer expiration time."
Too bad that the access token is not really valid forever...
According to "Exception 4" in this document , if you have Ads API access you should be able to get a non-expiring token if you use the correct workflow. Following the guidelines outlined here, if you use the server side OAuth flow, to make the following request you should get a non-expiring token:
GET /oauth/access_token?
grant_type=fb_exchange_token&
client_id={app-id}&
client_secret={app-secret}&
fb_exchange_token={short-lived-token}
thx for the feedback regarding the Access token process being cumbersome. Because this is a one to many solution - a single App ID can manage multiple ad accounts, on behalf of multiple people - we need to make calls on behalf of people.
You should be able to get a persistent access token for Ads API. If you are not getting it, please provide exact steps you are following so we can see if there is a bug or you might be missing a step.
Thx.

Facebook App, Wrong access token

I'm using the Graph Explorer, and I'm choosing my application from the Application Drop Down List.
I'm having to access this photo https://graph.facebook.com/399744030064153.
When i choose the application, facebook automatically the access token for the app and I'm being able to view the photo details.
However, in my php application, when i do
$access_token=$facebook->getAccessToken();
$photoObj=$facebook->api("https://graph.facebook.com/399744030064153?access_token=$access_token");
Its not working, from what i know, the access token is wrong because I'm trying to echo the access token and I check it. Thus, the problem is the access token
Does someone has an idea??
The Graph API explorer automatically generates a user access token, which gives the app the ability to act on a user's behalf. - in this case, your own account.
The getAccessToken() method in the SDK, if used standalone (i.e not as part of the documented Auth flow) will return an App Access Token, which although usable with the API won't be able to view any content unless it's Publicly visible

Application Token is Different

On this page:
http://developers.facebook.com/docs/opengraph/using-app-tokens/
It describes how to get the app access token, yet the token it returns is different than the one in the open Graph "Get Code" example. The latter is the only one that works. How can I get the second access token using the API? When I try to use the first example, I basically get something back that looks like "application ID|secret key" which is different than the real access token.
as documentation states, you will get
access_token=YOUR_APP_ACCESS_TOKEN
string back from the API call. Even though it LOOKS like "application ID|secret key HASH" - it is a valid access token you can use to publish to user's wall. You can verify it's a proper access token using Debug toll from FB: https://developers.facebook.com/tools/debug - just paste the token there.
The reason it might not work for you is because you are trying to publish something to the user's wall who did not authorize your app. Look here: https://developers.facebook.com/docs/reference/javascript/ - for example of how to use your app ID to make user authorize the app. You need to request publish_stream permission for your app from user in order to be able to publish as the app to the user's wall.
And going back to the documentation:
Note that the app access token is for publishing purposes permitted by
the publish_actions and publish_stream permissions. You will be unable
to retrieve information about the status update post with the given ID
using the app access token. Instead, you should use a user access
token for such purposes.
hope that helps.