Java Picasa API上载照片:获取403/无效令牌
我正在尝试将照片从Android应用程序上传到Picasa。我已经使用Google Single Sign-On登录并从那里检索了访问令牌 当尝试创建新相册时,我遇到了一个类似的错误,返回了无效的令牌 我可以拨打GET电话,检索公共相册和相册中的照片,但没有POST请求 下面是我如何尝试从存储上传照片Java Picasa API上载照片:获取403/无效令牌,java,android,picasa,Java,Android,Picasa,我正在尝试将照片从Android应用程序上传到Picasa。我已经使用Google Single Sign-On登录并从那里检索了访问令牌 当尝试创建新相册时,我遇到了一个类似的错误,返回了无效的令牌 我可以拨打GET电话,检索公共相册和相册中的照片,但没有POST请求 下面是我如何尝试从存储上传照片 String url = "https://picasaweb.google.com/data/feed/api/user/" + mPreferences.getUsername() + "/a
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());