我一直在寻找用于Google照片的API,这将使我可以在Android中创建一个应用程序,以将我的图片推到云中的特定专辑中。到目前为止,我已经看到了两个可能的解决方案:
1)Google Drive API-我昨晚实际上开发了一个POC,并且主要工作起作用,但不幸的是我无法指定一张Google Photos专辑以将我的图像发送到。
2)旧的picasaweb api-这个看起来更有前途,但我无法过去验证我的凭据。这是一篇Google文章,描述了如何设置此问题,但是Picasawebservice对象上的SetUserCredentials()方法不再功能(https://developers.google.com/picasa-web/docs/3.0/develice_java)
我想继续稍微追求选项2,但是我找不到该方法的方法或帐户意图)。我认为也许setusertoken()方法可以使用,我尝试插入我从上述两个登录方法中收到的令牌。我在我的oauth2范围" oauth2:profile电子邮件https://picasaweb.google.com/data/"中请求此信息,这确实提示我并问我是否想访问我的照片,我只是不知道如何将登录的用户帐户与Picasawebservice电话联系起来。
如果我从浏览器登录到我的Google帐户中击中此URL(此URL在上面链接的文章中),我会看到我期望看到的一切:https://picasaweb.google。com/data/feed/api/user/userame?chink =相册,所以我知道API仍然有效,我只是不知道如何在Android App中推高我的有效凭据。
任何建议将不胜感激tia
我没有亲自这样做,但请看一下这个人的回购。
https://github.com/tedyk/google-photos-android
希望能让您前进。
我曾经在2013 - 2014年一次工作。但是,关于关闭Picasa网络的讨论太多了,所以我从未将其投入生产。并非所有代码只是您要的身份验证...祝您好运。
//获取难以捉摸的令牌
if (TextUtils.isEmpty(token)) {
String SCOPE = "oauth2:http://picasaweb.google.com/data/";
try {
token = GoogleAuthUtil.getToken(context, email, SCOPE);
} catch (UserRecoverableAuthException e) {
token = "";
} catch (IOException e) {
token = "";
} catch (GoogleAuthException e) {
token = "";
}
if (TextUtils.isEmpty(token)) {
return null;
}
}
// send back to picasa
String urls = "https://picasaweb.google.com/data/entry/api/user/"
+ userId + "/albumid/" + albumId;
URL url = new URL(urls);
HttpURLConnection httpURLConnection = (HttpURLConnection) url
.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoInput(true);
httpURLConnection.setDoOutput(true);
httpURLConnection.setUseCaches(false);
// clientid may not be necessary is a crazy long string I think you get it from dashboard. it looks like blah.aps.googleusercontent.com
httpURLConnection.setRequestProperty("X-GData-Client", CLIENT_ID);
httpURLConnection.setRequestProperty("GData-Version", "2");
httpURLConnection.setRequestProperty("Authorization", "OAuth "
+ token);