从Google Photos API获取自己的数据(身份验证和请求) [英] Getting own data off Google Photos API (Authentication and requests)

查看:223
本文介绍了从Google Photos API获取自己的数据(身份验证和请求)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对使用API​​和React有点陌生,并对其进行测试,我正在编写一个项目,其中包括从我在Google相册中保存的特定相册中获取自己的媒体(或每个图像的URL) .目的是使该项目将我拍摄的所有照片(并放入此相册中)发布到具有响应的网站上.

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.

由于我只希望拥有自己的数据,并且不希望来自其他用户的任何信息/身份验证,所以我不能像大多数google照片文档所建议的那样登录(它只会获取他们的信息/图片,不是我的吗?).

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?).

我可以通过在配置(客户端ID/机密)以及范围中为其提供自己的凭据,然后在对话框中运行带有我需要的特定正文数据的POST请求,从而查看OAuth Playground的数据/URL,但是我如何将其与react一起使用,因为我每次拍摄新照片时都无法保持刷新令牌和手动输入URL的功能.

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.

推荐答案

Google相册api仅支持oauth2身份验证. 身份验证

Google Photos api only supports oauth2 authentication. Authencation

许多Google API具有此限制.您可以做的是创建一个服务器端脚本,该脚本将允许您登录并验证应用程序.确保请求离线访问.然后,这将向您返回刷新令牌.然后,您将可以在需要时使用刷新令牌来请求新的访问令牌.

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不会将刷新令牌返回给javascript应用程序,因为它们是客户端的.您将需要使用服务器端语言进行刷新令牌逻辑.

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.

从技术上讲,这些只是http帖子调用,因此您应该可以使用任何能够处理http帖子和获取内容的语言自行编写代码.我不是开发人员,所以不能为您提供更多帮助.

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.

这篇关于从Google Photos API获取自己的数据(身份验证和请求)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆