2011-05-12 45 views
0

我想通過我的應用程序在Android上使用Facebook Api將圖像上傳到我朋友的帳戶/牆上。 我可以將圖片上傳到我的帳戶,但現在我正在努力使其更加實用,並嘗試將圖片上傳到我通過Android應用程序選擇的朋友牆/帳戶上。 我試圖做到這一點,但沒有成功。 PLZ幫我... 由於提前在Facebook上通過Android上傳朋友牆/帳戶中的圖片

回答

1

使用此代碼在您的方法

File file=new File(murl); 
InputStream is; 
try { 
    is = new FileInputStream(file); 
    Drawable d; 
    long length = file.length(); 
    if (length > Integer.MAX_VALUE) { 
     // File is too large 
    } 
    byte[] bytes = new byte[(int)length]; 
    ByteArrayOutputStream bout=new ByteArrayOutputStream(); 
    // Read in the bytes 
    int offset = 0; 
    int numRead = 0; 
    while (offset < bytes.length 
      && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) { 
     offset += numRead;  
    } 
    bout.write(bytes); 
    bout.flush(); 
    //Bitmap bm=BitmapFactory.decodeByteArray(bytes,0,bytes.length); 
    //d=new BitmapDrawable(bm); 
    //mPostButton.setBackgroundDrawable(d); 
    //p.putString("to","1300750213"); 
    //p.putString("caption","my card"); 
    EditText title_txt=(EditText) findViewById(R.id.fb_upload_txt); 

    for(int i =0;i<frnd_list_id.length/2;i++){ 
     if(frnd_list_id[i]!="0"){ 
      Bundle p=new Bundle(); 
      p.putString("method","photos.upload"); 
      p.putString("caption",title_txt.getEditableText().toString()); 
      p.putByteArray("picture",bytes); 
      System.out.println(frnd_list_id[i].trim()); 
      p.putString("target_id",frnd_list_id[i].trim()); 
      mAsyncRunner.request(null,p,"POST",new WallPostRequestListener(),null); 
     } 
    } 
//System.out.println("hi"); 
} catch (Exception e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} 
+0

從w我明白,你最終會同時觸發'frnd_list_id.length/2'同時所有人向Facebook發送請求。猜測這可能是更好的策略來實現你自己的Thread,你可以同時多次同時調用'Facebook.request(...)'。 – harism 2011-05-14 21:03:41

相關問題