我正在尝试将照片从Android应用程序上传到Picasa。我已使用Google Single Sign On登录并从那里检索了访问令牌。
尝试创建新相册时,我收到类似的错误,返回无效令牌。
我可以进行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();
}
答案 0 :(得分:0)
通过更改
结束解决此问题httpPost.setHeader("Authorization", "GoogleLogin auth=" + mPreferences.getAccessToken());
到
httpPost.setHeader("Authorization", "OAuth " + mPreferences.getAccessToken());