android - 使用他们的 ID 将文件发布到我 friend 列表中选定的 friend

标签 android

我正在做一个示例 Facebook 应用程序,因为我必须将文件发布给特定的 friend 不要发布在我的 friend 列表中,不要在我的墙上发布它必须只对特定的人可见,我正在使用以下代码,它在默认的 Facebook Utll 类上给出错误和异常。如果可以更正,我会在这里发布我的代码,否则会提供一个好的解决方案……在此先感谢……

Bundle params = new Bundle();
            params=getIntent().getExtras();
            String new_data= params.getString("new_frdId");
            params.putString("method", "publish_stream");
            params.putString("access_token", UI_Friend_Finder.accesstoken);

            params
            .putString(
                    "attachment",
                    "{\"name\":\""
                            + "\",\"href\":\"http://www.google.co.in"
                            + "\",\"description\":\"
                            + "\",\"media\":[{\"type\":\"image\",\"src\":\""
                            + ""
                            + "\",\"href\":\""
                            + "\"}]}");
    authenticatedFacebook.dialog(PostToFriend.this, "stream_publish",
            params, new TestUiServerListener());

                       finish();
                                }

                });
}
class TestUiServerListener implements DialogListener {
    public void onComplete(Bundle values) {
        final String postId = values.getString("post_id");
        if (postId != null) {
            new AsyncFacebookRunner(authenticatedFacebook).request(postId,
                    new TestPostRequestListener());
        } else {
            PostToFriend.this.runOnUiThread(new Runnable() {
                public void run() {
                }
            });
        }
    }

    public void onCancel() {
    }

    public void onError(DialogError e) {
        e.printStackTrace();
    }

    public void onFacebookError(FacebookError e) {
        e.printStackTrace();
    }
}

public class TestPostRequestListener implements RequestListener {
    public void onComplete(final String response, final Object state) {
        try {
            JSONObject json = Util.parseJson(response);
            String postId = json.getString("id");
            PostToFriend.this.runOnUiThread(new Runnable() {
                public void run() {
                    Log.d("Tests", "Testing wall post success");
                }
            });
        } catch (Throwable e) {
        }
    }

    public void onFacebookError(FacebookError e, final Object state) {
        e.printStackTrace();
    }

    public void onFileNotFoundException(FileNotFoundException e,
            final Object state) {
        e.printStackTrace();
    }

    public void onIOException(IOException e, final Object state) {
        e.printStackTrace();
    }

    public void onMalformedURLException(MalformedURLException e,
            final Object state) {
        e.printStackTrace();
    }
}

public class TestLoginListener implements DialogListener {
    public void onComplete(Bundle values) {
        if (authenticatedFacebook.isSessionValid() == true) {
            String response = null;
            JSONObject jObject = null;
            try {
                jObject = new JSONObject(
                        authenticatedFacebook.request("me"));
            } catch (MalformedURLException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (JSONException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            editor.commit();

            finish();
        }
    }

    public void onCancel() {
    }

    public void onError(DialogError e) {
        e.printStackTrace();
    }

    public void onFacebookError(FacebookError e) {
        e.printStackTrace();
    }
} 

最佳答案

这是代码..我将 stream.publish 方法放在请求函数中..它运行良好..

protected void postToWall(String temp2) {
   System.out.println("<<inside the post method>>");
   Bundle params = new Bundle();
   params.putString("message", _messageInput.getText().toString()"some text Here);
   params.putString("caption", "{*actor*} just posted a secret message.");
   params.putString("description","A secret message is waiting for you.  Click the link to    decode it.");
   params.putString("name", "A Secret Message For You");
 params.putString("picture","http://www.kxminteractive.com/Content/images/app_logos/secretMessage.png");
  params.putString("link", "http://www.kxminteractive.com/decrypt/");
  **mAsyncRunner.request(((temp2 == null) ? "me" : temp2) + "/feed",
                params, "POST", new WallPostRequestListener(),stream.publish);**
}

关于android - 使用他们的 ID 将文件发布到我 friend 列表中选定的 friend ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6138215/

相关文章:

android - 通知未决 Intent 的问题

java - 从 ArrayList 中删除某些 TextView

android - Android 多帐户的 clearPackagePreferredActivities 异常

android - 以编程方式防止使用 USB 端口

android - flutter 模拟器错误 |找不到路径为 : platforms;android-R 的平台 SDK

android - PreferenceScreen 中的文本大小

android - ListView 编辑器的 UI 设计

java - 日期选择器中的日期翻转日和月

java - 如何验证俄语电子邮件?

android - 通过 HCE 模拟信用卡