2011-11-06 122 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(); 
     } 

    }