Get an access token from Instagram API WITHOUT a browser? - http

I'm working on a project where I pull in data from social media according to certain queries and analyze them. Currently I'm pulling in Instagram media data.
The only thing I want to do is to input a query and get JSON media/likes/comments.... I read the documentation of their API. I found that I couldn't get an access token without authorizing using my own account in a browser. I know there's gotta be a user, so I assume using my own account is fine. But the problem is that I don't want to get an access token manually from a browser.
Currently I'm hardcoding the access token. It will expire and I have to update it manually every time. I bet there's a better solution. Could someone help me out? Thanks.
class instagramFeed():
CLIENT_ID = "MY-APP-ID"
REDIRECT_URI = "MY-ORGANIZATIONS-URI"
ACCESS_TOKEN = "I MANUALLY GENERATE THIS TOKEN"
query = None
def __init__(self):
None
def get_data(self, query):
response = urllib2.urlopen("https://api.instagram.com/v1/tags/search?q="+query+"&access_token="+self.ACCESS_TOKEN)

It is not possible to get access_token without logging in on Instagram page, thats the whole point of oauth authentication.
You will have to manually get access_token and update, from my experience the Instagram access_token never expires, I have used it for 6 years. Only time you have to get new access_token is if Instagram revokes it because of suspicious activity detected. So as long as you use the API carefully without automating too much back-to back calls, you should be good with the same access_token.

Related

Invalied token error in google calendar api

I'm using google calendar api to addd events tocalendar. When I'm using oauth2.0, its asking for oauth and working properly. but after 2 0r 3 try, its failing, it shows invalied token error. And again after some times it work properly.
And if I use the token stored, its asking for oauth2 for the first 1 or 2 attempts and its fine. but its not asking for oauth and no events are being created. agin after some tries its asking for oauth2.
I didn't get any Idea why its happening so. Is there any solution?
This is probably occurring because your tokens are expiring. Include access=offline and prompt=consent in the authorization code link and it will probably start to work. Also make sure to refresh your token of the original access token fails and call the API with the new access token.
I work with Pathfix and it takes off the exact hassle for you if you want to save some time with the OAuth dance :)

How to properly initiate an OAuth flow for Gmail Watch?

I'm trying to initiate Gmail Watch on behalf of my site's users and also get the messages according to what historyId I get on the corresponding PubSub Topic.
I have GCP + Firebase on the backend and Angular 7 in the frontend.
I face two problems here:
Doing this on the frontend seems the right way, with grantOfflineAccess, since it asks nicely on the consent screen for the required Modify scope. However, what I get back is an auth code, and I can't find out how to get access and refresh tokens from it, and use it in the backend Cloud Functions python part.
If I try this on the backend (which works), I have to initiate the flow from python, send the redirect to Angular and pop-up the consent url there. This already seems bad, since the consent screen does not say anything about what you're granting. Then I need a redirect url, which can't be a Cloud Functions url, because I can't whitelist it (can verify the domain), so it is now handled on the Angular side and sent back. Ie. the my oauth redirect is handled in the frontend, which also doesn't seem the right way.
Could you please advise on how to do this properly?
Thanks!

Google Analytics - a way to submit query from Query Explorer via API

There is an API in place and available to me (v4 compatible), but for various reasons it's not working correctly and there is not much time to fix it (too many other fires). So the idea was floated that that to bypass most of the issues with API here it might be a quick-fix to send whole query to GA.
It needs to be automated and results stored in our DB (Webservice on MS Stack), else we would do it manually all the way, which is out of the question at this time.
Hence the question:
IS there a way to submit a query that is exactly the product of a Query Explorer via API or any other way and retrieve it's results?
The API Query URI returned by the Query Explorer
https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A78110423&start-date=30daysAgo&end-date=yesterday&metrics=ga%3Ametric1
Is for the Google Analytics v3 api. To use this in your own code you must simply attach a valid access token to the end of the request.
https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A78110423&start-date=30daysAgo&end-date=yesterday&metrics=ga%3Ametric1&access_token=XXXX
This is not going to be using the Google Analytics v4 API that is a different call entirely.
Access tokens can be retrieved from either service account authentication or Oauth2 authentication and must be valid for the view you are requesting data for.

It is possible to authenticate in Yammer and Outlook with rest api?

I am trying to integrate Yammer and Outlook using the Rest API, I can read the emails but I have an error returned when reading data from yammer. The documentation is unclear about it, can they help?
You need to follow one of the authentication flows outlined within a browser window.
Typically you would popup a window with a browser control to do this work and then securely store the OAuth token returned. I recommend working through the flow by hand before writing code to integrate it. It is expected that a user sees and has to agree to an OAuth dialog like the one shown.
You then pass the token on the authorization header like this with your HTTP requests:
Authorization: Bearer TOKEN_HERE
Perfect Brian, but I'm using Graph's endpoint, I'd like to use Outlook and Yammer together.
var authEndpoint = 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize?';
var apiEndpoint = 'https://graph.microsoft.com/api/v2.0';
I would not like to authenticate again, is it possible?
You'd need to add resource=https://www.yammer.com param to the authEndpoint to be able to access yammer data. See this blog post for further details - https://blogs.technet.microsoft.com/israelo/2016/07/05/yammer-apis-and-adal-tokens/

Using Google Analytics to show subset of data for customers of web application using embed api

I'm developing an application where each 'business' has its own page (or rather many pages):
For example example.com/business/abc/
So, for the logged in business owners in the system I would like to give a feature 'View page analytics'. It would display how many visits (and maybe a couple of other things) that particular page has had.
Is there a way of doing this using the Google Analytics API with my constraints:
I don't want customers to provide their own UA code
I don't want them to require to have GA account
Customers don't need to have Google email account
I don't want to build the entire frontend and backend myself. I would rather use something existing
I've been researching this topic for hours trying to come up with a solution and can't figure out anything.
Here is what I tried and what problems happened to me:
http://ga-dev-tools.appspot.com/demos/embed-api/
This is basically exactly what I want for my customers to be displayed on my site (like in the examples), except that Embed Api tries to authorize users to their own (owned) google analytics. I want it instead to use my own Google Analytics data (or rather part of it)
The way I thought about limiting data access would be for every one of my customers to create a View in GA, Add filter to that View so only customer pages are listed there, assign User to the view, and use the Embed Api to display data from that View only. There are a couple of problems with that:
To assign User to View we need email address. And this must be either google account email, or account from a project created with Google Developers Console (application).
In other words I can't create (in any way that I know) an account that would be a shield account for my customers to a subset of my GA data that they would be interested in. It must be either a real user or a real application email address.
So what I tried to do is... I created an app in Google Developers Console, Created new OAuth Service Account. Using Ruby code (that in production app would be running on backend) I obtained OAuth token. I added this email of my OAuth service account as a User to the View
I wanted this server side generated oauth token to be used by Embed Api. That would achieve the effect that I generate the token for on my backend and user can use it without having GA user in my GA property. So I changed according to documentation the basic Embed Api example to use
gapi.analytics.auth.authorize({
container: 'auth',
clientid: 'xxx.apps.googleusercontent.com',
serverAuth: {
access_token: 'Server side generated token'
}
});
instead of
gapi.analytics.auth.authorize({
container: 'auth',
clientid: 'xxx.apps.googleusercontent.com',
});
The effects are not quite what I expected. The example doesn't show anymore (I can't see my data) but I can see in Netowrking section in Chrome that it is actually receiving real data from GA. But for unknown reason, nothing is appearing.
What I try to avoid is building a solution in which I need to build server side code that is querying GA for data, providing it to the frontend and then JS is responsible for displaying it. I would rather use Embed API but it seems not to be well suited for the use case where I don't want users to play with their UA data but rather with my own UA data limited to some scope. I would like to have at least the frontend or backend part of the solution solved. The solution doesn't need to be even Google Analytics based. Anything else that would let me achieve the use case easily and let the business owners see the effects of their marketing (traffic, sales) would be interesting as well.
Related:
Using google analytics API to show subset of data for customers of web application
Google analytics customer data?
Google Analytics API: filter by URI?
https://embeddedanalytics.com seems like something that could be useful, but their page and graphs look like from a few years ago. I would like something more pretty.
https://oocharts.com seems to be interesting because of what their docs.oocharts.com says about queries. But they don't charge anything for their product so I am skeptical of their business model and whether it is a good long-term solution. update: dead link
I don't have enough karma to post links ;)
TLDR: Displaying subset of my GA data to my customers without forcing them to become GA users and adding them to my GA account.
Any help appreciated!
Without seeing your code it's hard to know where the problem is, but using the serverAuth option definitely works. And when using the serverAuth option, you don't need to specify a client ID or container, all you need to enter is the following:
gapi.analytics.auth.authorize({
serverAuth: {
access_token: 'Server side generated token'
}
});
Here's an example that will work if you enter in a valid access token and the idsfor a view to which you have access:
http://jsbin.com/vukezoheyeco/3/edit
Note: when doing auth like this, it happens sync. This can be a gotcha if you're used to an async auth flow (like normal) and you add an event handler listening for the "success" event after calling .authorize because then your handler will never run.
I think you need the Google Analytics Super Proxy
You download the github package and upload to your own App Engine project, do some minimal configuration and then you have an interface where you can setup Google Analytics API calls which require no user login.
It provides end user URLs that you can use to construct data tables in your front end, it also provides data-table format so it slots right into Google Charts.
So for example, you have a user that needs access to visits, revenue for site section /sectionA/
You set up the GA super proxy to serve them a URL that only includes data for that section - you can try out queries here in the GA query explorer. In this case, metrics=ga:visits,ga:productRevenue and filter~=ga:page=/sectionA/
This produces an end URL with JSON data, that refreshes daily/hourly - your choice. You import this URL into your app.
The end user then logs in to your app, and sees the chart data generated from the end URL for their login. They don't need to know about GA super proxy, they just see the end resulting chart.
You could get more sophisticated by providing dropdowns to select which data chart they see, which changes the GA super proxy URL that is requested.

Resources