Picasa API 上传照片:获取 403/无效令牌

Picasa API Upload Photo: Getting 403/Invalid Token

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

尝试创建新相册时,我收到类似 returns 无效令牌的错误。

我可以进行 GET 调用以检索 public 相册和这些相册中的照片,但没有 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();
}

最终通过更改

解决了这个问题
httpPost.setHeader("Authorization", "GoogleLogin auth=" + mPreferences.getAccessToken());

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