简体   繁体   English

从Google Photos API获取自己的数据(身份验证和请求)

[英]Getting own data off Google Photos API (Authentication and requests)

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. 我对使用API​​和React有点陌生,为了进行测试,我正在编写一个项目,其中包括从我在Google相册中保存的特定相册中获取自己的媒体(或每个图像的URL)。 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?). 由于我只希望拥有自己的数据,并且不希望来自其他用户的任何信息/身份验证,所以我不能像大多数Google照片文档所建议的那样登录(它只会获取他们的信息/图片,而不是我的? )。

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. 我可以通过在配置(客户端ID /秘密)以及范围中为其提供自己的凭据,然后在对话框中使用所需的特定正文数据运行POST请求,来查看OAuth Playground的数据/ URL。将此功能与react配合使用,因为每次拍摄新照片时,我都无法仅不断刷新令牌并手动输入URL。

Google Photos api only supports oauth2 authentication. Google Photos api仅支持oauth2身份验证。 Authencation Authencation

A number of google apis have this limitation. 许多Google API具有此限制。 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. Google不会将刷新令牌返回给javascript应用程序,因为它们是客户端的。 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. 如果我记得最后一次,在oauth2游乐场上创建的令牌的生命周期约为两个小时。 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. 从技术上讲,这些只是http post调用,因此您应该可以使用任何可以处理http post和get的语言编写此代码。 I am not a react developer so cant help you more then that. 我不是开发人员,所以不能为您提供更多帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM