FB Ads Insights API : get the access token using credentials - facebook

I am new to FB's API
I need to use FB Ads Insights API to pull the stats and store in DB. This is my customer's requirement. Now, I have a Developer account and access to my customer's username and pwd, how can I use their credentials and get the access token to query Insights API
TIA,

Use this guide to generate an access token. You will have to create a system user that has access to your customer's account.

Related

Google Analytics API - how do I get access tokens without being an Admin

I'm very new to using APIs and I'm struggling to figure out the authentication. With my email I can log in to a corporate analytics page and view the information. My account is only at a 'user' level. How do I get access tokens so I can scrape the data from the page using the Google API? Do I need the admins of the page to get these tokens? I tried using the generate access token but I don't know the service account email. Any advice would be appreciated because I'm so confused.
Answer: how do I get access tokens without being an Admin
As long as your personal account has read access you can use Oauht2 to authorize your application and then be able to access the data that way you do not need to be admin.
All your other questions 😊
How do I get access tokens so I can scrape the data from the page using the Google API?
First off if you use Oauth2 in your application and login with your own user you you will be able to use the Google Analytics api as you have read access thats all you need for the Google analytics api in order to request data.
Do I need the admins of the page to get these tokens?
No anyone with read access can authorize an application to access the google analytics api.
I tried using the generate access token but I don't know the service account email.
Service accounts are completely different than normal Oauth2. A service account is a dummy user which needs to be preauthorized to access the data it has nothing to do with your personal access. To preauthorize a service account to access the google analytics api you will need to have admin access to the google analytics account and take the service ac count email address and add it as a user on the google analytics account. It will then have access to read the data.
Any advice would be appreciated because I'm so confused.
Decide if your application should be allowing users to login to it and access the data on their own google analytics accounts. If so then you should be using Oauth2 and not a service account.
If you are only trying to access this single google analytics account then you should be using a service account. However you will need to contact the admin to have them grant your service account access to the data.

How to model Facebook access tokens and user accounts

I'm building an app that allows users to sign up with facebook login. Facebook login gives us an expiring access token.
So far I've thought through having the phone app collect the facebook access token itself and it should POST it to the api. The api can search to see if it's seen this token before and if it hasn't the api should generate a new user account.
However the facebook docs mention that this token expires. If a user's token expires and they provide a new token to my api, the api will generate a new account for the existing user. How should I solve this?
Use the access token to access https://graph.facebook.com/me?fields=id, which will give you the user's unique ID for your application. Use that as the primary key.
You can try this out with the graph explorer tool https://developers.facebook.com/tools/explorer/
You'll get a response like
{
"id": "10123455041265200"
}
Docs https://developers.facebook.com/docs/graph-api/reference/user/

How to generate Facebook Marketing API access token to use it in Windows application

I am using Facebook as advertising platform to promote my application on Apple and Google stores. I would like to make windows service which will download daily report(s) about advertising status of my marketing campaign running one Facebook, preferably using 60 day token, or some permanent solution so that token is retrieved when required. I think that i understand everything to do this except how to generate access token to use it with Facebook Graph API. Which token for which Facebook account do I need and how to obtain it?
You'll need a Facebook app and to grant that app the ads_read permission in order to retrieve reports about your advertising efforts via the API (source).
You'll want a long-lived token so that you don't have to re-authenticate very often. The access token documentation details the steps to exchange a short-lived token for a long-lived one.
You may also want to consider managing the app, ad account, and access tokens (via a business system user) with the FB Business Manager.
Create a facebook app.
Go to the Graph API Explorer in Facebook's Tools & Support section.
Pick your app from the drop down.
Hit Get Token > Get User Access Token.
In Select Permissions choose required permissions or select them from extended permissions.
Use the user access token that will be presented to you in the access token form input field.

Can I access the Facebook Audience Network API using a revokable token?

My company makes an ad network mediation product. We use each ad network's API to aggregate their stats on one dashboard. In order to do this for Facebook Audience Network, we currently have the developer give us their App ID and App Token, as per the Reporting API docs. As far as we can tell, though, the App Token isn't revokable, which makes some of our developers uneasy about sharing it.
Is there a way to access the Facebook Audience Network API using a revokable token, or a way to revoke an App Token?
According to the documentation at developers.facebook.com/docs/graph-api/reference/v2.1/app/… : "A user access token with read_insights permission can retrieve metrics for all apps owned by this user".
So just have the user login to your app and grant read_insights to your app.

Facebook access_token for my application is not working while access_token of graph API is working

there is a problem with my access token. I have made my own application, and I took the permission from the facebook user, who is me. And also I have given the same permissions to the facebook graph api. However when I can easily get the results using FQL with graph api access token, but I cannot get the result with my own application access token. What is the problem with my access token.
It is not user access token. Maybe this can be problem however also graph api is not also user access token.
Per the error message you need to use a user access token retrieved via the Authentication flow - you cannot use an app access token for this.
You mentioned in the comments you're successfully using an access token from the Graph API Explorer tool - this is also a user access token which the tool retrieves using the client-side oauth flow. This is not the same as using an app access token for your own app.