2011-11-06 117 views
0

我有這段代碼在我的應用程序中運行,它試圖將文本和圖像發佈到用戶牆上。目前它只發布文本。我想我已經錯過了一些簡單的東西,但希望另一雙眼睛檢查一切或另一個樣本。Android發佈圖像到Facebook

任何幫助是極大的讚賞。

  Bundle bundle = new Bundle(); 
      bundle.putString("message", "test update"); //'message' tells facebook that you're updating your status 
      bundle.putString(Facebook.TOKEN,accessToken); 
      bundle.putString("attachment", "{\"name\":\"My Test Image\"," 
+"\"href\":\""+"http://www.google.com"+"\"," 
+"\"media\":[{\"type\":\"image\",\"src\":\""+"http://www.google.com/logos/mucha10-hp.jpg"+"\",\"href\":\""+"http://www.google.com"+"\"}]" 
+"}"); 
        +"}"); 
      //tells facebook that you're performing this action on the authenticated users wall, thus 
//   it becomes an update. POST tells that the method being used is POST 
      String response = facebook.request("me/feed",bundle,"POST"); 

回答

0

對於Facebook塗鴉牆發佈文字和圖片,check this link

您可以使用Media附件插入圖片。

2

希望這將是對你的工作

對於Facebook varible實用

進口android.app.Application創建類;

import com.facebook.android.AsyncFacebookRunner; 
import com.facebook.android.Facebook; 

public class Utility extends Application{ 
    public static Facebook mFacebook; 
    public static AsyncFacebookRunner mAsyncRunner; 
    public static String userUID; 
    public static final String ICON_URL = "http://i.imgur.com/6G1b7.png"; 

} 

現在馬託用於張貼圖片的Facebook牆上

public void postOnFacebookPicture(final Bitmap bitmap) { 

     String access_token = mPrefs.getString("access_token", null); 
     long expires = mPrefs.getLong("access_expires", 0); 

     if (access_token != null) { 
      Utility.mFacebook.setAccessToken(access_token); 

     } 
     if (expires != 0) { 
      Utility.mFacebook.setAccessExpires(expires); 
     } 

     if (!Utility.mFacebook.isSessionValid()) { 
      showErrorDialog(
        "Facebook Account is not configure,Setting Facebook Account?", 
        new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int id) { 
          try { 
           // Move to setting the facebook account 
          } catch (Exception e) { 
           // TODO Auto-generated catch block 
           e.printStackTrace(); 
          } 

         } 
        }, new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int id) { 
          dialog.cancel(); 

         } 
        }); 
     } else { 
      new Thread() { 
       @Override 
       public void run() { 
        int what = 0; 

        try { 

         String accessToken = mPrefs.getString("access_token", 
           null); 

         ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
         bitmap.compress(CompressFormat.PNG, 0, bos); 
         byte[] pictureData = bos.toByteArray(); 

         Bundle bundle = new Bundle(); 
         bundle.putByteArray("facebookPictureData", pictureData); 
         bundle.putString(Facebook.TOKEN, accessToken); 

         Utility.mFacebook.request("me/photos", bundle, "POST"); 

        } catch (Exception e) { 
         what = 1; 
        } 

        mHandler.sendMessage(mHandler.obtainMessage(what)); 
       } 
      }.start(); 
     } 

    }