使用Facebook sdk 3.1在Facebook帖子的消息字段中嵌入链接

时间:2013-09-11 08:11:50

标签: android facebook-sdk-3.0

我需要嵌入显示here的链接,其中包含日期和时间。我知道“链接” 字段我们可以嵌入post的链接。但我希望链接在消息字段中像超链接。

1 个答案:

答案 0 :(得分:0)

尝试这种方式:

private void publishStory(String youneed, String other, String user) {

        Session session = Session.getActiveSession();
        if (session != null){
            // Check for publish permissions    
            List<String> permissions = session.getPermissions();
            if (!isSubsetOf(PERMISSIONS, permissions)) {
                pendingPublishReauthorization = true;
                Session.NewPermissionsRequest newPermissionsRequest = new Session
                        .NewPermissionsRequest(getActivity(), PERMISSIONS);
                session.requestNewPublishPermissions(newPermissionsRequest);
                return;
            }
            Bundle postParams = new Bundle();

// here you are making your profile post
            postParams.putString("name", title);
            postParams.putString("caption", "By Recommend Android");
            postParams.putString("description", user+" "+"STRONGLY recommends"+" "+title);
            postParams.putString("link", "http://re.co/"+hash);
            postParams.putString("picture", "http://re.co/assets/img/useful-exp.png");

            Request.Callback callback= new Request.Callback() {
                public void onCompleted(Response response) {
                    JSONObject graphResponse = response
                            .getGraphObject()
                            .getInnerJSONObject();
                    String postId = null;
                    try {
                        postId = graphResponse.getString("id");
                    } catch (JSONException e) {
                        Log.i(TAG,
                                "JSON error "+ e.getMessage());
                    }
                    FacebookRequestError error = response.getError();
                    if (error != null) {
                        debug.print("erreur");
                    } else {
                        debug.print("erreur2");
                    }
                }
            };
            Request request = new Request(session, "me/feed", postParams, 
            HttpMethod.POST, callback);
            RequestAsyncTask task = new RequestAsyncTask(request);
            task.execute();
        }
    }
    private boolean isSubsetOf(Collection<String> subset, Collection<String> superset) {
        for (String string : subset) {
            if (!superset.contains(string)) {
                return false;
            }
        }
        return true;
    }