Invalied token error in google calendar api - 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 :)

Related

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 Oauth client was deleted. can I restore a new one?

We running a wordpress website use google oauth for third-party social login. (via WP Social Login plugin.) Former engineer is leave, and we cannot have past google account credential.
We face a problem shows:
Error 401
Error: deleted_client
The OAuth client was deleted.
but we can only see old client id and secret from website admin panel.
I wanna to know,
if we set up a new google oauth application id/secret, will it make user crash from login website?
Or, is it possible for us to restore/retrieve former application ownership and make it live again?
This happened to me when I was working on an Add-On (maybe not completely related to this question but similar). I mistakenly deleted a Client ID that I thought we weren't using.
How I solved it:
Created a new project in Google Cloud
Associated the Apps Script project (Add-on) to this new Google Cloud project
Then I re-associated the App Script project with my previous Google Cloud project
The previous step will re-compile, create and associate the Client ID to the App Script project. It will contain all settings from the Client ID manually created and associated with your project in the code.
Maybe this will give some light to anyone having a similar problem.
Here use this link:
https://support.google.com/cloud/answer/6251787?hl=en
You have to reach google and they will help you out, this is the only solution you can do.
In my case, the simplest/only path (though certainly not ideal) ended up being to create a new Firebase project and start using that.
This of course can be problematic if you have a lot of data to move and/or a nontrivial data schema - say, with nested collections. For me, it was worth the effort to get unblocked from Sign-In suddenly failing to work.
... ah, OAuth fun
=======
If you are trying to make the new Client ID work .. though it's not a total solution, but after searching for a while, found this config option in Firebase console - where you enable Google Sign In.
So if you generate a new OAuth Client ID, update the ID & secret there.
After I did this, it went from a 401 error to a 400 mis_direct , which I think was step in the right direction.

Get an access token from Instagram API WITHOUT a browser?

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.

LinkedIn New API - Can't Get r_network Permission

I inherited a program that was written with the old LinkedIn API, and I'm trying to migrate it to the new API. When I try to get the r_basicprofile permission, my oauth token works. However, when I try r_network or rw_nus, I get a response
invalid scope -- your application has not been authorized for
r_network.
Yet, when I go to www.linkedin.com/developer/apps/xxxx/auth, the boxes for r_network and rw_nus are checked.
I.e., A request to
https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=xxxxxx&scope=r_basicprofile&state=yyyy&redirect_uri=http%3A%2F%2Fkalatublog.com%2Fwp-content%2Fmu-plugins%2Fimb-en%2Fhelpers%2Fsocial-connect%2Fapi%2Ffinalize.php%3Fapi%3Dlinkedin%26ch%zzzzz
works, but a request to
https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=xxxxxx&scope=r_network&state=yyyy&redirect_uri=http%3A%2F%2Fkalatublog.com%2Fwp-content%2Fmu-plugins%2Fimb-en%2Fhelpers%2Fsocial-connect%2Fapi%2Ffinalize.php%3Fapi%3Dlinkedin%26ch%zzzzz
gives that error. What am I doing wrong?
As of May 15,
After the grace period expires, several REST API endpoints will no longer be available for general use. The following endpoints are the only ones that will remain available for use:
Profile API — /v1/people/~ `
Share API — /v1/people/~/shares
Companies API — /v1/companies/{id}
If your application is currently using any other API services (e.g. Connections, Groups, People Search, Invitation, Job Search, etc.) you will have to apply to become a member of a relevant Partner Program that provides the necessary API access to continue to leverage any of the endpoints that are not listed above.
It looks like linkedin no longer wants to share anything with their API. Creating a new app indicates that the only possible options are r_basicprofile, r_emailaddress, rw_company_admin, and w_share:
TLDR: they have locked down the API and restricted the usage to an extremely limited set of access points.
I did some more digging. The linkedin website is misleading. On my app linkedin page, it says that I'm approved for rw_nus and r_network, but on this page
https://developer.linkedin.com/support/developer-program-transition
it says those are no longer approved.
So the app home page in linkedin incorrectly said I had those permissions.
Heres the link if you want to Apply for Linkedin
https://help.linkedin.com/app/ask/path/api-dvr

Google calendar API calls blocked by captcha

I have successfully written a tool to display upcoming calendar events on a website using Google's calendar API (v2). I am using the username/password method outlined at https://developers.google.com/google-apps/calendar/v2/developers_guide_dotnet#AuthClientLogin. Today an instance of this code would not return data or a decent error message. I finally logged into the web server and browsed directly to http://calendar.google.com and logged in using the credentials. I was challenged by Google's captcha and then my code worked.
How do I get around API calls being blocked by Google's captcha security? I don't want to have to re-code for magic cookies but I will if I have to. I have read some about generating tokens but I dont know if that is something I have to do once or every time the code is called.
If your app is a service that is getting used by many people, you might be running into API call bandwidth limitation. That is, google is limiting the number of API requests per time interval.
If this IS getting used by many people, you may have to upgrade to a paid account.

Resources