Facebook的的Andr​​oid的Open Graph? [英] Android Facebook Open Graph?

查看:332
本文介绍了Facebook的的Andr​​oid的Open Graph?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇,如果我能得到一些帮助的Open Graph,因为我似乎无法作出任何意义了,我已阅读Facebook的API的。

I am curious if I can get some help with Open Graph since I can't seem to make any sense out of the Facebook API that I have read.

现在我已经安装在Facebook上我的Open Graph应用。它已被批准。我试图通过捆绑PARAMS提交我的对象,但我很好奇我怎么设置捆绑参数对象如下所示。其中, myObject的有与之关联的多个值。

Right now I have setup my Open Graph Application on Facebook. It has been approved. I am trying to submit my "objects" via the bundle params but I am curious how I setup a bundle param object like the following. Where myObject has multiple values associated with it.

Bundle params = new Bundle();
param.putString("myObject", ""); // My object has multiple values

我想我真的需要弄清楚如何在具有多个与之相关的属性包提交的东西。如果任何人有这个任何见解,请帮助我。

I guess I really need to figure out how you submit something in the Bundle that has multiple properties associated with it. If anyone has any insight on this please help me out.

起初,我曾试图这样的事情。

At first I had tried something like this.

Bundle myObject = new Bundle();
myObject("property1", "property1Value");
myObject("property2", "property2Value");
myObject("property3", "property3Value");
Bundle params = new Bundle();
params.putString("myObject", myObject); 

但事后我想通了,为什么这是行不通的。

But in hindsight I figured out why this wouldn't work.

修改1

这也许会提供一些​​线索。请记住,这是一个开放图谱行动,这不是图形API的一部分。

Maybe this will shed some light. Keep in mind this is an Open Graph action which is not a part of the Graph API.

//Build recipe
JSONObject recipe = new JSONObject();
recipe.put("type", "myappns:recipe");
recipe.put("recipe_name", "Thai Island");
recipe.put("cook_time", "1hr. 30min.");

//Build cookbook
JSONObject cookbookParams = new JSONObject();
cookbookParams.put("type", "myappns:book");
cookbookParams.put("title", "Hot & Spicy");
cookbookParams.put("description", "This book consists of hot & spicy foods");
cookbookParams.put("recipes", new JSONArray().put(recipe));


Bundle params = new Bundle();
params.putString("cookbook", cookbookParams.toString());
AsyncFacebookRunner request = new AsyncFacebookRunner(facebook);
request.request("me/myappns:used", params, "POST", new addToTimelineListener(), null);

下面是一个问题,但正如我一直在挖掘更多的进入打开图系统。我相信我需要真正有一个网站设置的地方,这是正确的?我是率先通过开放图谱的介绍文档,我可以创建和使用Android上我的Facebook应用程序,而无需任何网站相信。这就是使用开放图谱系统,我知道我可以使用应用程序发布的饲料,什么不可以,我已经成功地完成。

Here is a question though as I have been digging more into the Open Graph system. I believe I need to actually have a website setup somewhere, is this correct? I was lead to believe through the introductory documentation of Open Graph that I could create and use my Facebook application on Android without the need of any website. That is use the Open Graph system, I know I can use the application to post feeds and what not which I have done successfully.

再次感谢!

编辑2

甚至不担心回答我明白我的问题是什么,现在......我必须有一个网站的某个地方托管的帖子链接回过一个Facebook应用程序。非常有意义,我还没有看到那里的文档对此很直接的......哦,现在好了,我知道了。

Dont even worry about replying I understand what my problem was now...I have to have a website somewhere hosting a Facebook application for the posts to link back too. Makes perfect sense, I haven't seen where the documentation was very direct about this...oh well now I know.

推荐答案

我用这个code到墙壁上的多个对象属性发布。

I use this code to publish on wall for multiple object properties.

     private void publishPhoto(String imageURL) {
    Log.d("FACEBOOK", "Post to Facebook!");

    try {

        JSONObject attachment = new JSONObject();
        attachment.put("message",text);
        attachment.put("name", "MyGreatAndroidAppTest");
        attachment.put("href", "http://stackoverflow.com/users/909317/sunny");
        attachment.put("description","Test Test TEst");

        JSONObject media = new JSONObject();
        media.put("type", "image");
        media.put("src",  imageURL);
        media.put("href",imageURL);
        attachment.put("media", new JSONArray().put(media));

        JSONObject properties = new JSONObject();

        JSONObject prop1 = new JSONObject();
        prop1.put("text", "Text or captionText to Post");
        prop1.put("href", imageURL);
        properties.put(text, prop1);

        // u can make any number of prop object and put on "properties" for    ex:    //prop2,prop3

        attachment.put("properties", properties);

        Log.d("FACEBOOK", attachment.toString());

        Bundle params = new Bundle();
        params.putString("attachment", attachment.toString());
        facebook.dialog(MyProjectActivity.this, "stream.publish", params, new DialogListener() {

            @Override
            public void onFacebookError(FacebookError e) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onError(DialogError e) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onComplete(Bundle values) {
                final String postId = values.getString("post_id");
                if (postId != null) {
                    Log.d("FACEBOOK", "Dialog Success! post_id=" + postId);
                    Toast.makeText(MyProjectActivity.this, "Successfully shared on Facebook!", Toast.LENGTH_LONG).show();

                } else {
                    Log.d("FACEBOOK", "No wall post made");
                }

            }

            @Override
            public void onCancel() {
                // TODO Auto-generated method stub

            }
        });      

    } catch (JSONException e) {
        Log.e("FACEBOOK", e.getLocalizedMessage(), e);
    }
}

这篇关于Facebook的的Andr​​oid的Open Graph?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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