在 Android 上使用 Facebook API 创建自定义墙贴 [英] Creating a custom Wall Post with Facebook API on Android

查看:17
本文介绍了在 Android 上使用 Facebook API 创建自定义墙贴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Android 上 Facebook API 的新手,基本上,我要做的是为我正在开发的应用程序创建自定义墙贴.就像当您听 Shazam 一首歌时,您可以与您的朋友分享结果.我相信我必须创建一个自定义附件.这是我设置附件的代码:

I'm new to Facebook API on Android, and basically, what I'm trying to do is creating custom wall post for an application I'm developing. Like when you listen a Shazam a song and you can share the result with your friends. I believe I've got to create a custom attachment. Here's my code for setting the attachment:

mPostButton.setOnClickListener(new OnClickListener() {

    public void onClick(View v) {
        Bundle myParams = new Bundle();
        String attachment="{\"name\":\"Gran Turismo 5\"," +
           "\"href\":\"http://www.unknown.com/?lang=fr\"," +
           "\"caption\":\"Sony Computer Entertainment\",\"description\":" +
           "\"Une vidéo proposée par Cedemo.\",\"media\":" +
           "[{\"type\":\"image\",\"src\":" +
           "\"http://www.unknown.com/prepicture//thumb_title/15/15061_1.jpg\"," +
           "\"href\":\"http://www.unknown.com/?lang=fr\"}],\"properties\":" +
           "{\"Autre lien\":{\"text\":\"Cedemo\",\"href\":\"http://www.unknown.com\"}}}";
        myParams.putString("attachment", URLEncoder.encode(attachment);
        mFacebook.dialog(Option.this, "stream.publish",myParams,
                new SampleDialogListener());

然后,稍后:

public class SampleDialogListener extends BaseDialogListener {

    public void onComplete(Bundle values) {
        final String postId = values.getString("post_id");
        if (postId != null) {
            Log.d("Facebook-Example", "Dialog Success! post_id=" + postId);
            mAsyncRunner.request(postId,values, new WallPostRequestListener());
        } else {
            Log.d("Facebook-Example", "No wall post made");
        }
    }
}

我没有写附件字符串,它只是从本论坛中的另一个问题中提取的测试.无论如何,当我调用 myAsync.request 时,我的应用程序显示一条错误消息,我应该如何将附件传递给我的对话框?希望我已经足够清楚了.

I didn't wrote the attachment String, It's just a test taken from another question made in this forum. Anyway, when I call myAsync.request, my app shows an error message, how am I supposed to pass the attachment to my dialog? Hope I've been clear enough.

推荐答案

您确定需要设置自定义参数吗?听起来您可能只想直接在墙上发布 Facebook 消息:您可以通过简单地将消息参数作为字符串提交来实现这一点——如果您想附加图像等,您只需要所有 JSON.并注意在 facebook 的页面上,它说使用这个 api 调用不会发布其他人可以在他们的提要上看到的状态更新,它只会出现在他们的 自己的墙.如果您只想发布带有链接的消息,您应该可以使用您的 mAsyncRunner(一旦您拥有有效的 Facebook 会话):

Are you sure you need to set custom parameters? It sounds like you can just want to post a Facebook message directly to the wall: you can do this by simply handing in the message parameter as a string -- you only need all that JSON if you want to attach an image etc. And note on facebook's page it says using this api call won't post a status update that others can see on their feed, it will just appear on their own wall. If you just want to post a message with a link you should just be able to use your mAsyncRunner (once you have your valid Facebook session) using this:

String message = "Post this to my wall";
Bundle parameters = new Bundle();        
parameters.putString("message", message);   
mAsyncRunner.request("me/feed", parameters, "POST", new WallPostRequestListener());

如果您发布了从 Facebook 获得的错误/响应代码,也可能会有所帮助.

Also may help if you posted the error/response code you're getting from Facebook.

这篇关于在 Android 上使用 Facebook API 创建自定义墙贴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆