繁体   English   中英

使用FACEBOOK SDK 3.6将消息/照片从Android发布到Facebook

[英]Posting message/Photo from Android to Facebook using FACEBOOK SDK 3.6

我正在使用SDK 3.6发布消息和照片。 以下代码给出了类似“ Unsupported Methods,Photos.upload”的响应

我在下面提到了Stackoverflow。

Android将图片发布到Facebook墙上

有什么问题吗?。 如何上传图像(不是从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;
  }
}

我删除了它并发布了它。

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

并使用以下几行消息将其与图像一起成功发布。

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

如果您具有发布权限,请尝试此代码

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();

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM