2012-04-05 7 views
0

メタデータのない写真をPicasaウェブアルバムにアップロードすると、エラーが発生しました(403は禁止)。 (メモ:それはOAuth2.0を使用しています。 "userId"はGmailのアドレス[数値ID]ではありません) 私は機会がわかりません。 誰でもしてください技術サポート 感謝Picasaウェブアルバムのメタデータなしで写真を投稿する(結果403禁止)

public String setdData(Context context, String filePath, String userId, String albumId, String accessToken) { 

    // new ImageUploader(context, filePath, filePath).run(); 
    String url = "https://picasaweb.google.com/data/feed/api/user/" + userId + "/albumid/" 
     + albumId; 
    HttpClient httpClient = new DefaultHttpClient(); 
    File file = new File(filePath); 
    HttpPost httpPost = new HttpPost(url); 
    httpPost.setHeader("GData-Version", "2"); 
    // httpPost.addHeader("MIME-version", "1.0"); 
    httpPost.setHeader("Content-type", "image/jpeg"); 
    httpPost.setHeader("Slug", "plz-to-love-realcat.jpg"); 
    // httpPost.addHeader("Content-Length", String.valueOf(file.length())); 
    httpPost.setHeader("Authorization", "GoogleLogin auth=" + accessToken); 
    // httpPost.setHeader("Authorization", "OAuth " + accessToken); 

    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) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (ClientProtocolException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
} 

答えて

1

私はこれが私のコードであり、それは私の作品...あなたのaccessTokenがnullでないことを

を想定しています:

public boolean setdData(Context context, String filePath, String userId, String albumId, String accessToken) { 
    boolean success = false; 
    Bitmap bitmap = BitmapFactory.decodeFile(filePath); 

    if (bitmap != null) { 
     try { 
      ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
      bitmap.compress(Bitmap.CompressFormat.JPEG, 87, baos); 
      byte[] data = baos.toByteArray(); 

      ByteArrayInputStream inputStream = new ByteArrayInputStream(data); 
      HttpRequestFactory requestFactory = new NetHttpTransport().createRequestFactory(); 
      InputStreamContent content = new InputStreamContent("image/jpeg", inputStream); 

      HttpRequest request = requestFactory.buildPostRequest(new genericUrl("https://picasaweb.google.com/data/feed/api/user/"+userId+"/"+albumId+"/default"), content); 
      GoogleHeaders headers = new GoogleHeaders(); 
      String fileName = "Whatever..."; 
      headers.setSlugFromFileName(fileName); 
      headers.setAuthorization("OAuth " + accessToken); 
      request.setHeaders(headers); 
      request.execute().ignore(); 
      // Success! 
      success = true 
     } catch (IOException e) { 
     } 
    } 
    return success; 
} 


このコードを機能させるには、いくつかのライブラリを含める必要があります。

グーグル-HTTPクライアント-1.10.2-beta.jar
グーグル-API-クライアント-1.10.2-beta.jar
グーグル-のOAuthクライアント-1.10.0-:
は、私はこれらを使用しました
は jsr305-1.3.9.jar
グアバ-11.0.1.jar

あなたはここでそれらを見つけることができますbeta.jar:
http://code.google.com/p/google-api-java-client/downloads/detail?name=google-api-java-client-1.10.2-beta.zip

関連する問題