android facebook api post to wall with image

前端 未结 2 598
滥情空心
滥情空心 2021-02-02 02:50

I would like to be able to use the facebook android sdk and post a link to facebook. An example of what I want would be is if you were on facebook and you type a link into your

2条回答
  •  终归单人心
    2021-02-02 03:27

    Asuming when you read this that you know how to log onto facebook and such via the api...

      private void fbImageSubmit(Facebook fb, String imageurl, String caption, String description, String name, String linkurl)
        {
            if(fb != null)
            {
                if(fb.isSessionValid())
                {
                    Bundle b = new Bundle();
                    b.putString("picture", imageurl);
                    b.putString("caption",caption);
                    b.putString("description",description );
                    b.putString("name",name);
                    b.putString("link",linkurl);
                    try {
                        String strRet = "";
                        strRet = fb.request("/me/feed",b,"POST");
                        JSONObject json;
                        try {
                            json = Util.parseJson(strRet);
                            if(!json.isNull("id"))
                            {
                                Log.i("Facebook", "Image link submitted.");
                            }
                            else
                            {
                                Log.e("Facebook","Error: " + strRet);
                            }
                        } catch (FacebookError e) {
                            Log.e("Facebook","Error: " + e.getMessage());
                        }
                    } catch (Exception e) {
                        Log.e("Facebook", "Error: " + e.getMessage());
                    }
                }
            }
        }
    

提交回复
热议问题