0

我正在尝试使用 android facebook sdk 在wallpost 中标记一个朋友。但是,应该是标签的东西是空白的,什么都没有。这是我使用的代码:

            Bundle params = new Bundle();
            access_token = fb.getAccessToken();

            try {
                params.putString("format", "json");
                params.putString("access_token", access_token);
                String url = "https://graphs.facebook.com/me/friends";
                String response = Util.openUrl(url, "GET", params);
                JSONObject json = Util.parseJson(response);
                JSONArray array = json.optJSONArray("data");

                for(int i = 0; i < array.length(); i++) {
                    String tempName = array.getJSONObject(i).getString("name");
                    String tempID = array.getJSONObject(i).getString("id");

                    //Probably should have some if-tests here

                    if(tempName.contains(*nameOfFriend*)) {
                        Bundle bundle = new Bundle();
                        bundle.putString("message", "App tagging test");
                        //this is where the tagging is supposed to happen
                        bundle.putString("tags", *UserID*);
                        try {
                            fb.request("me/feed", bundle, "POST");
                            Toast.makeText(getApplicationContext(), "Tag-test", Toast.LENGTH_SHORT).show();
                        } catch (MalformedURLException e) {
                            Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
                            e.printStackTrace();
                        } catch (IOException e) {
                            Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
                            e.printStackTrace();
                        }
                    } else {
                        Toast.makeText(getApplicationContext(), "Couldn't find friend", Toast.LENGTH_SHORT).show();
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

我只授予了“publish_stream”的权限,难道我需要其他权限吗?提前感谢您的帮助,伙计们!

4

2 回答 2

2

以下是标记朋友的工作代码此外,您必须向 fb 提交您在 devlepoer facebook 帐户中创建的项目的 Taggable Friends api 功能的评论。在您获得提交批准后,以下代码将标记您的朋友。

     Bundle params = new Bundle();
    params.putString(Facebook.TOKEN, facebook.getAccessToken());
    params.putString("method", "photos.upload");
    params.putString("caption", ShareTripActivity.tripNotes); // text to post

    if(ShareTripActivity.arr_facebookID.size()>0)
    {
        String tagFriendListId="";
        for(int i=0;i<ShareTripActivity.arr_facebookID.size();i++)
        {

            tagFriendListId = tagFriendListId+"{'tag_uid':'"+ShareTripActivity.arr_facebookID.get(i)+"'} ,";

        }
        tagFriendListId=tagFriendListId.substring(0, tagFriendListId.length()-1);
         params.putString("tags","["+tagFriendListId+"]");

    }
   AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
    mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null);

//示例上传监听

公共类 SampleUploadListener 扩展 BaseKeyListener 实现 RequestListener {

    public void onComplete(final String response, final Object state)
    {
        try
        {
            // process the response here: (executed in background thread)
            Log.d("Facebook-Example", "Response: " + response.toString());
            JSONObject json = Util.parseJson(response);
            final String src = json.getString("src");

            // then post the processed result back to the UI thread
            // if we do not do this, an runtime exception will be generated
            // e.g. "CalledFromWrongThreadException: Only the original
            // thread that created a view hierarchy can touch its views."

        }
        catch (JSONException e)
        {
            Log.w("Facebook-Example", "JSON Error in response");
        }
        catch (FacebookError e)
        {
            Log.w("Facebook-Example", "Facebook Error: " + e.getMessage());
        }
    }

    public void onFacebookError(FacebookError e, Object state)
    {
        // TODO Auto-generated method stub

    }

    public Bitmap getInputType(Bitmap img)
    {
        // TODO Auto-generated method stub
        return img;
    }

    public int getInputType()
    {
        // TODO Auto-generated method stub
        return 0;
    }

    public void onIOException(IOException e, Object state)
    {
        // TODO Auto-generated method stub

    }

    public void onFileNotFoundException(FileNotFoundException e, Object state)
    {
        // TODO Auto-generated method stub

    }

    public void onMalformedURLException(MalformedURLException e, Object state)
    {
        // TODO Auto-generated method stub

    }
}

在这个 arr_facebookID 中是包含您要标记的朋友的 facebook_user_id 的数组列表。

于 2014-11-13T04:03:57.363 回答
0

place我在您的代码中看不到任何值,但在通过 API 发布的帖子中标记人员时需要这样做。

https://developers.facebook.com/docs/reference/api/user/#posts

标签 [...] 注意:如果不指定地点,则无法指定此字段。

于 2012-07-17T12:52:08.183 回答