Tokens : Access token issues by a user - google-admin-sdk

Folks,
I am trying to figure out a way to get the list of the users that are using Google Drive for desktop in our Google workspace environment. Since there is no direct way of getting this information, i found an article online where one get this info by following the steps below:
List all the users of your domain
(https://developers.google.com/admin-sdk/directory/reference/rest/v1/users/list)
Check for each user, based on client id, what is the response
received using tokens: get
(https://developers.google.com/admin-sdk/directory/reference/rest/v1/tokens/get)
I was successful in getting the list of users but need help on how to get information around the token response for each user( I have the app client ID). Can someone help?

Related

How to get a valid access token to query search result from Facebook graph API

I want to collect all the Facebook link from Facebook search function. What I'm using here is the Facebook graph API tool.
If I want to query the data for a keyword, for example: "limited";
I will use the URL:
https://graph.facebook.com/v11.0/search?q=limited&access_token={my_access_token}
My image
However, I got the result as in the image. When I tried to create a workplace app and tried to get the access token of that app, I got the message as in the second image.
Error message when getting the access token of a workplace app
What I need now is an access token that has the permission to retrieve the data from the Facebook search. After that, I can use python to handle the rest.
Please help me out, thank you very much!

How can I authenticate users via social account from mobile app using retrofit2?

I'm trying to connect my website's API and mobile app. I need to authenticate the user with google account but I don't know how to do it.
I created the backend with Django. And I set the endpoint as rest-auth/google/. On the restframework's page, it requires Access Token and Code but honestly I don't get how I can test if it actually works using actual google account.
I want to test from mobile app but I don't understand how and what I need to POST.
Anyone could give me tips?
I would recommend you to use a ready solution like "django-allauth".
If you want to do authentication yourself you might want to read Google's documentation about the topic:
https://developers.google.com/api-client-library/python/
In nutshell you create API credentials:
https://console.cloud.google.com/apis/credentials
Send a user to a link with specific parameters (api-credentials, scope, redirect link etc). Google client can help you to generate it.
A user will login in his account as he would normally do and will give your app permissions to use his information (or won't). After that he will be redirected to the link you specified with GET request with a code as a parameter (or error).
With help of Google client you can exchange the code on a token and then use that token to get information from his profile.

Instagram Graph API

My task is to get photo data of my business Instagram account with Instagram Graph API. I followed the instruction from Instagram Graph API -
https://developers.facebook.com/docs/instagram-api/reference/user/media
, which said request like
GET http://graph.facebook.com/17841405822304914/media
can get photo data from the Instagram account linked to the FB account in JSON format.
I tried to send GET request /my_facebook_id/media as said by the document with Graph API Explorer on FB developer platform but it failed to return the data I want.
This is the error I got:
message: Tried accessing nonexisting field (media) on node type (User)
type: OAuthException code: 100
Does the message mean the media field doesn't exist in the FB user?
What is the meanIng of error code 100? I can't even see that in FB official document.
I tried to use the Instagram business account ID for this request but I got an error message said the user object doesn't exist
How to get the task done? Thanks!
I guess you have missed creating a Facebook business page and linking your Instagram Business account to it.
Here is the guide to setup : https://developers.facebook.com/docs/instagram-api/getting-started
If this was done correctly and still you're facing the error is because of a Facebook bug where your account doesn't get linked correctly.
Here : https://developers.facebook.com/support/bugs/177912116363088/?disable_redirect=0
Solution : Please disconnect your Instagram account from your page. Then, on Instagram app, in setting you will have to switch back to personal account and reconvert to a business account
Note : Switching to a personal account you will lose the insights of your media.
Once this is done you should be able to get instagram_business_account and post which you can run your query to fetch the media :
GET http://graph.facebook.com/you-instagram-business-account-id/media

Unable to find Facebook Page Insights using Page Access Token in RestFB

I have to develop an automated process for fetching my Facebook page insights. Since, Access token used for authentication purpose is temporary in nature. Therefore, I created a Facebook App and by providing all required permissions I generated a Page Access Token so that I could extend it's life-span.
Reference Link : Java + RestFB API: Getting fresh Page Access Token without messing with AppID, appSecret
The following is my piece of code :
FacebookClient fb=new DefaultFacebookClient(accesstoken,Version.VERSION_2_7);
Connection<Insight> insights =fb.fetchConnection("119456244790112/insights", Insight.class,Parameter.with("since", "2016-08-01"),Parameter.with("until", "2016-08-27"));
for (Insight insight : insights.getData())
if(insight.getName().equals("page_impressions") && (insight.getPeriod().equals("day")) )
System.out.println(insight.getName()+"\t"+insight.getPeriod()+"\t"+insight.getValues());
'accesstoken' is the short-life Page access-token obtained by following the mentioned link.
The following is the Exception Stack I'm getting :
Exception in thread "main"
com.restfb.exception.FacebookOAuthException: Received Facebook error
response of type OAuthException: Invalid query (code 3001, subcode
1504028) at
com.restfb.DefaultFacebookClient$DefaultGraphFacebookExceptionMapper.exceptionForTypeAndMessage(DefaultFacebookClient.java:1191)
at
com.restfb.DefaultFacebookClient.throwFacebookResponseStatusExceptionIfNecessary(DefaultFacebookClient.java:1117)
at
com.restfb.DefaultFacebookClient.makeRequestAndProcessResponse(DefaultFacebookClient.java:1058)
at
com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:969)
at
com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:931)
at
com.restfb.DefaultFacebookClient.fetchConnection(DefaultFacebookClient.java:356)
at Main.main(Main.java:31)
Please help me finding the Page Insights using Page Access Token and hence extending it's life-span so that I could produce an automated process out of this. Thanks !
You asked two questions in one.
Extending an access token:
First, you need the user access token. Than extend it (Check the RestFB manual: http://restfb.com/documentation/#access-token-extend) and take the page access token for the page from /me/accounts. The page access token has an unlimited lifetime.
The OAuthException:
If you look at the error message of the exception you should see that the metric is missing. You nee to tell Facebook what metric you like to get. Check the Graph API Reference for valid metrics: https://developers.facebook.com/docs/graph-api/reference/v2.7/insights
Finally I got the success in pulling the Page Insights data using the 'Page Access Token' with extended life-span.
The following is the snippet for making the appropriate requests to Facebook :
Connection<Insight> insights =fbclient.fetchConnection("1388062484542431/insights/page_views/day", Insight.class,Parameter.with("since", "2016-08-01"),Parameter.with("until", "2016-08-30"));
If multiple Metrics need to be passed then we can do so by passing comma-separated names of the required Metrics.
Thanks.

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.