其他分享
首页 > 其他分享> > Android Facebook Open Graph?

Android Facebook Open Graph?

作者:互联网

我很好奇我能否在Open Graph方面获得帮助,因为我似乎对阅读的Facebook API没有任何意义.

现在我已经在Facebook上设置了我的Open Graph应用程序.已被批准.我试图通过bundle params提交我的“对象”,但我很好奇如何设置如下的bundle param对象.其中myObject具有与其关联的多个值.

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

我想我真的需要弄清楚您如何在捆绑包中提交具有多个关联属性的内容.如果有人对此有任何见解,请帮助我.

起初我尝试过类似的方法.

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

但是事后看来,我想出了为什么这行不通.

编辑1

也许这会有所启发.请记住,这是一个开放图谱操作,它不是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);

不过,这是一个问题,因为我一直在深入研究Open Graph系统.我相信我实际上需要在某个地方设置网站,这正确吗?通过Open Graph的入门文档,我被认为可以在不需要任何网站的情况下在Android上创建和使用我的Facebook应用程序.那就是使用开放图谱系统,我知道我可以使用该应用程序发布提要,而我没有成功完成.

再次感谢!

编辑2

甚至不用担心回答,我明白我的问题了……我必须在某个网站上托管一个Facebook应用程序,以便帖子也可以链接回去.完全有道理,我还没有看到文档中最直接的相关信息……我现在知道了.

解决方法:

我使用此代码在墙上发布多个对象属性.

     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", "https://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 one rror(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);
    }
}

标签:android,facebook,facebook-opengraph
来源: https://codeday.me/bug/20191013/1907652.html