问题
I'm a bit new to using APIs and React and to test it out I'm writing a project that includes getting my own media (or just the URLs of each image) off of a specific album I have on Google Photos. The aim is that the project will post any photos I take (and put in this album) onto a site with react.
Since I only want my own data and I don't want any information/authentication from other users I can't just have a sign in as most of the google photos documentation suggests (it would just get their information/pictures and not mine?).
I can see the data/URLs off of OAuth Playground by giving it my own credentials in the configurations (client ID/secret) plus the scope and then running a POST request with the specific body data I need in the dialogue boxes but how can I use this with react since I can't just keep refreshing the tokens and inputting the URLs manually whenever I take a new picture.
回答1:
Google Photos api only supports oauth2 authentication. Authencation
A number of google apis have this limitation. What you can do is create a server sided script that will allow you to login and authenticate your application. Make sure to request off line access. This will then return to you an refresh token. You will then be able to use your refresh token to request a new access token when ever you need.
Google does not return a refresh token to javascript applications as they are client sided. You will need to use a server sided language for the refresh token logic.
refresh Tokens created on the oauth2 play ground have a life time of about two hours if last i remember. I am not sure if this is also true with tokens created using your own client.
Technically these are just http post calls so you should be able to code this yourself in any language that can handle http post and get. I am not a react developer so cant help you more then that.
来源:https://stackoverflow.com/questions/52832007/getting-own-data-off-google-photos-api-authentication-and-requests