【问题标题】:Posting message/Photo from Android to Facebook using FACEBOOK SDK 3.6使用 FACEBOOK SDK 3.6 从 Android 向 Facebook 发布消息/照片
【发布时间】:2014-02-01 15:32:47
【问题描述】:

我正在使用 SDK 3.6 发布消息和照片。下面的代码给出了类似“不支持的方法,Photos.upload”的响应

我参考了下面的 Stackoverflow。

Android post picture to Facebook wall

有什么问题吗?如何上传图片(不是来自 url),并在 facebook 中一起发送消息

private void postPhoto1()
{
if (hasPublishPermission()) {
Bitmap image = BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_launcher);
Session session = Session.getActiveSession();
Bundle postParams = new Bundle();
Byte[] data = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
postParams.putString("method", "photos.upload");
postParams.putByteArray("picture", data);
Request request = new Request(session, "me/photos", postParams, HttpMethod.POST, new Request.Callback() {
     @Override
   public void onCompleted(Response response) {
   showPublishResult(getString(R.string.successfully_posted_post), response.getGraphObject(), response.getError());
  }
 });
     RequestAsyncTask task = new RequestAsyncTask(request);
     task.execute();
      } else {
   pendingAction = PendingAction.POST_PHOTO;
  }
}

【问题讨论】:

    标签: android facebook facebook-graph-api


    【解决方案1】:

    我删除了这个并发布了它。

    postParams.putString("method", "photos.upload");
    

    使用下面的几行消息,它还与图像一起成功发布。

    postParams.putByteArray("picture", data);
    postParams.putString("message", messageval );
    

    【讨论】:

      【解决方案2】:

      如果您获得发布许可,请尝试此代码

      public void postImage(){
           byte[] data = null;               
      
           File imagefile = new File(Path);
              FileInputStream fis = null;
              try {
                  fis = new FileInputStream(imagefile);
                  } catch (FileNotFoundException e) {
                  e.printStackTrace();
              }
      
              Bitmap bm = BitmapFactory.decodeStream(fis);
               ByteArrayOutputStream baos=new  ByteArrayOutputStream();
               bm.compress(Bitmap.CompressFormat.JPEG,100, baos);             
              data = baos.toByteArray();                
              Bundle params = new Bundle();              
              params.putString(Facebook.TOKEN, facebook.getAccessToken());              
              params.putString("method", "photos.upload");              
              params.putByteArray("picture", data);               
              AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);              
              mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null);   
              Toast.makeText(getApplicationContext(), "Image Posted on Facebook.", Toast.LENGTH_SHORT).show();
      
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-09-13
        • 1970-01-01
        • 2011-08-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多