2012-05-21 67 views
0

這裏的文件是上傳照片到我的facebook代碼:上傳圖片到FB從Android的:沒有錯誤,但沒有上傳至Facebook

Bundle parameters = new Bundle(); 
parameters.putString("message", msg); 
byte[] imgData = getImage("http://bandungraos.in/wp-content/resto/1/gallery/kepiting1.jpg"); 
parameters.putByteArray("picture", imgData); 
if (imgData != null) { 
    try { 
     String response = facebook.request("me/photos", parameters,"POST"); 
      System.out.println(response); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
} 
..... 

private byte[] getImage(String url) { 

    try { 
     URL imgUrl = new URL(url); 
     HttpURLConnection cn = (HttpURLConnection) imgUrl.openConnection(); 
     cn.setDoInput(true); 
     cn.connect(); 
     int length = cn.getContentLength(); 
     byte[] imgData = new byte[length]; 
     InputStream is = cn.getInputStream(); 
     is.read(imgData); 
     return imgData; 

    } catch (MalformedURLException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

    return null; 

} 

我檢查,要麼訪問令牌或imgData不爲空

沒有錯誤,但我無法在我的臉書上找到圖像。

在此先感謝

+0

也許你的形象正在等待你的FB批准公佈 –

+0

郵件是否能張貼和公正的圖像丟失,或者整個後從供給缺失? –

回答

0

按照User object文件有關Photos connection圖像參數被命名爲「源」而不是「圖片」,你有沒有嘗試過:

Bundle parameters = new Bundle(); 
parameters.putString("message", msg); 
parameters.putByteArray("source", getImage("...")); 
+0

謝謝。我試過使用圖片,源代碼和圖片,但沒有修復它。 – user1134475

0

我同樣的問題,我用這個代碼'

private void upload_FB(Bitmap photo2) { 
     // TODO Auto-generated method stub 
     Calendar c = Calendar.getInstance(); 
     String name = c.getTime().toString(); 

     AsyncFacebookRunner fruner = new AsyncFacebookRunner(facebook); 
     Log.d("adr", mCurrentPhotoPath); 
     if(photo2!=null && mCurrentPhotoPath!=null){ 
      ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
      photo2.compress(Bitmap.CompressFormat.JPEG, 100, baos); 
      byte[] bMapArray = baos.toByteArray(); 
      Bundle params = new Bundle(); 
      params.putByteArray("photo",bMapArray); 
      params.putString("caption", name); 
      fruner.request("me/photos",params,"POST",new PhotoUploadListener(),null); 


     }else 
      Toast.makeText(ctx, "ERROR", Toast.LENGTH_LONG).show(); 
    } 

不要忘記添加premision photo_upload `

相關問題