Problems when creating Open Graph reports: "Could not create history" and "Could not create preview",

I have a Facebook application (we will call it mygame) related to the Android game that I am developing. In this mobile application, I want users to share their scores after the match. For this, I examined the use of Open charts, actions, and objects .

The first thing I did was create a “Play” action and a “Match” object, this one with the whole “score” property. After that, I created my first story in the form of "Play the match" using the relative button "Add user story".

First problem: all generated examples do not show preview, instead there is a red message Unable to Generate Story.enter image description here

This problem was previously discussed in Stackoverflow, and the reason was that “ facebook has no examples of history for rendering . This should not be true in my case, because if I open Object Browser , I see two automatically generated Match objects. Is Facebook trying to generate examples from these posts? If not (or even true), what is the problem?

Second problemSOLVED, SEE ANSWERS: on Android, simply, I cannot check this story due to the exception that says com.facebook.FacebookException: Failed to generate preview for user..

, Facebook " ", : https://developers.facebook.com/docs/android/open-graph#sharedialog-setup

:

        OpenGraphObject setObj = OpenGraphObject.Factory.createForPost("mygame:match");
        setObj.setProperty("score", set.getThisUserScore());
        setObj.setProperty("title", set.getType().getDisplayString());
        setObj.setProperty("url", "http://www.mygame.com");
        setObj.setProperty("description", "Can you beat me?");

        OpenGraphAction action = GraphObject.Factory.create(OpenGraphAction.class);
        action.setType("mygame:play");
        action.setProperty("match", setObj);

        FacebookDialog shareDialog = new FacebookDialog.OpenGraphActionDialogBuilder(activity, action, "match").build();
        activity.getUiHelper().trackPendingDialogCall(shareDialog.present());

, , .

, ( ). ?

+4
2

FacebookException! :

setObj.setProperty("score", set.getThisUserScore());

"" , :

setObj.getData().setProperty("score", set.getThisUserScore());

, , ...

0

.

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

}

+1

Source: https://habr.com/ru/post/1526520/


All Articles