【问题标题】:Picasa API Upload Photo: Getting 403/Invalid TokenPicasa API 上传照片:获取 403/无效令牌
【发布时间】:2016-04-01 00:54:26
【问题描述】:

我正在尝试将照片从 Android 应用程序上传到 Picasa。我已经使用 Google Single Sign On 登录并从那里检索了访问令牌。

在尝试创建新专辑时,我收到类似的错误,返回 Invalid Token。

我可以进行 GET 调用来检索公共相册和这些相册中的照片,但没有 POST 请求。

这是我尝试从存储中上传照片的方式

String url = "https://picasaweb.google.com/data/feed/api/user/" + mPreferences.getUsername() + "/albumid/" + mAlbumID;
HttpClient httpClient = new DefaultHttpClient();

File file = new File("/storage/emulated/0/Pictures/Screenshots/scrn.png");

HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("GData-Version", "2");
httpPost.setHeader("Content-type", "image/jpeg");
httpPost.setHeader("Slug", "plz-to-love-realcat.jpg");
httpPost.setHeader("Authorization", "GoogleLogin auth=" + mPreferences.getAccessToken());

InputStreamEntity reqEntity;
org.apache.http.HttpResponse response;

try {
    reqEntity = new InputStreamEntity(new FileInputStream(file), file.length());

    String CONTENTTYPE_BINARY = "binary/octet-stream";
    reqEntity.setContentType(CONTENTTYPE_BINARY);
    reqEntity.setChunked(true);
    httpPost.setEntity(reqEntity);
    response = httpClient.execute(httpPost);

    Log.d("Picasa Upload", "STATUS CODE : " + response.getStatusLine().getStatusCode());

} catch (FileNotFoundException e) {
    e.printStackTrace();
} catch (ClientProtocolException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}

【问题讨论】:

    标签: java android picasa


    【解决方案1】:

    最终通过改变解决了这个问题

    httpPost.setHeader("Authorization", "GoogleLogin auth=" + mPreferences.getAccessToken());
    

    httpPost.setHeader("Authorization", "OAuth " + mPreferences.getAccessToken());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-15
      • 1970-01-01
      • 2012-03-12
      • 2011-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多