Android Facebook Open Graph?

前端 未结 2 2041
南旧
南旧 2021-01-25 10:59

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.

Right now I have setup my Open Graph

2条回答
  •  孤城傲影
    2021-01-25 11:52

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

提交回复
热议问题