【问题标题】:Android Post Message to Facebook Wall Without Open DialogBox?Android 在没有打开对话框的情况下向 Facebook 墙发布消息?
【发布时间】:2012-10-29 11:41:26
【问题描述】:

我正在做一个应用程序,在该应用程序中,我想在不打开对话框的情况下将消息发布到 facebook 墙上。

我的完整脸书墙邮编:

Facebook mFacebook = new Facebook("xxxxxxxxxxxxxxxx");//MY APP ID
        Log.d("Tests", "Testing graph API wall post");
        try {
            String response = mFacebook.request("xxxxxxx");//USER ID
            Bundle parameters = new Bundle();
            parameters.putString("message", "hi hi hi");
            parameters.putString("description", "test test test");
            response = mFacebook.request("xxxxxxxx/feed", parameters,"POST");
            if (response == null || response.equals("") || 
                    response.equals("false")) {
                Log.v("Error", "Blank response");
            }
        } catch(Exception e) {
            e.printStackTrace();
        } 

此代码显示错误,

logcat 错误:

10-27 23:19:53.369: WARN/System.err(9330): java.net.MalformedURLException: Protocol not found: me?format=json
10-27 23:19:53.369: WARN/System.err(9330):     at java.net.URL.<init>(URL.java:273)
10-27 23:19:53.369: WARN/System.err(9330):     at java.net.URL.<init>(URL.java:157)
10-27 23:19:53.369: WARN/System.err(9330):     at com.whitehorse.Facebook.Util.openUrl(Util.java:151)
10-27 23:19:53.369: WARN/System.err(9330):     at com.whitehorse.Facebook.Facebook.request(Facebook.java:564)
10-27 23:19:53.369: WARN/System.err(9330):     at com.whitehorse.Facebook.Facebook.request(Facebook.java:500)
10-27 23:19:53.369: WARN/System.err(9330):     at com.whitehorse.birthdayreminder.DetailsPage.PostMessageToWall(DetailsPage.java:202)
10-27 23:19:53.369: WARN/System.err(9330):     at com.whitehorse.birthdayreminder.DetailsPage.access$1(DetailsPage.java:197)
10-27 23:19:53.369: WARN/System.err(9330):     at com.whitehorse.birthdayreminder.DetailsPage$3.onClick(DetailsPage.java:149)
10-27 23:19:53.369: WARN/System.err(9330):     at android.view.View.performClick(View.java:2485)
10-27 23:19:53.369: WARN/System.err(9330):     at android.view.View$PerformClick.run(View.java:9080)
10-27 23:19:53.369: WARN/System.err(9330):     at android.os.Handler.handleCallback(Handler.java:587)
10-27 23:19:53.369: WARN/System.err(9330):     at android.os.Handler.dispatchMessage(Handler.java:92)
10-27 23:19:53.369: WARN/System.err(9330):     at android.os.Looper.loop(Looper.java:130)
10-27 23:19:53.369: WARN/System.err(9330):     at android.app.ActivityThread.main(ActivityThread.java:3687)
10-27 23:19:53.369: WARN/System.err(9330):     at java.lang.reflect.Method.invokeNative(Native Method)
10-27 23:19:53.369: WARN/System.err(9330):     at java.lang.reflect.Method.invoke(Method.java:507)
10-27 23:19:53.379: WARN/System.err(9330):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
10-27 23:19:53.379: WARN/System.err(9330):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
10-27 23:19:53.379: WARN/System.err(9330):     at dalvik.system.NativeStart.main(Native Method)

请给一些关于facebook SDK的建议,

谢谢,

【问题讨论】:

    标签: android facebook facebook-graph-api


    【解决方案1】:

    这是我用于我的应用程序的代码,用于在没有对话框的情况下将消息发布到 Facebook 墙上:

    Facebook facebook = new Facebook(MY_APP_ID);
    AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
    Bundle params = new Bundle();
    params.putString("caption", "My Caption");
    params.putString("description", "description here");
    params.putString("picture", "http://nyan-cat.com/images/nyan-cat.gif");
    params.putString("name", "name string");
    params.putString("message", "my message here");
    mAsyncRunner.request("me/feed", params, "POST", new RequestListener() {
        @Override
        public void onFacebookError(FacebookError e, final Object state) {
            Log.e("Facebook", e.getMessage());
            e.printStackTrace();
        }
    
        @Override
        public void onFileNotFoundException(FileNotFoundException e, final Object state) {
            Log.e("Facebook", e.getMessage());
            e.printStackTrace();
        }
    
        @Override
        public void onIOException(IOException e, final Object state) {
            Log.e("Facebook", e.getMessage());
            e.printStackTrace();
        }
    
        @Override
        public void onMalformedURLException(MalformedURLException e, final Object state) {
            Log.e("Facebook", e.getMessage());
            e.printStackTrace();
        }
    
    }
    

    【讨论】:

    • 如何声明我没有的 mAsyncRunner 和 RequestListener 类。请分享新的 RequestListener() 并解释 mAsyncRunner??
    • AsyncFacebookRunner inside mAsyncRunner.request("me/feed", params, "POST", new RequestListener()) 此方法不可用。 mAsyncRunner.request 这个方法显示错误。什么是对象状态??
    • 方法可用,例如这个 public void request(final String graphPath, final Bundle parameters, final String httpMethod, final RequestListener listener, final Object state) { } 如何发送状态。什么是对象状态??
    【解决方案2】:
    Facebook facebook = new Facebook(APP_ID);
    AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
    Bundle params = new Bundle();
    Bundle params = new Bundle();
    params.putString("message", Message);
    String resp= "";
    try {
        resp = mAsyncRunner.request("me/feed", params, "POST");
    /*
    There are not only one request function in the SDK.(with different parameter)
    Try the read the source code in the SDK. 
    There are brief remarks on each function and parameters.
    You can post wall with above request function and get the postID with the following code.
    */
    } catch (FileNotFoundException e) {
    } catch (MalformedURLException e) {
    } catch (IOException e) {
    }
    try{
        resp = new JSONObject(resp).getString("id");//POST ID Here
    }catch(JSONException e1){
    }
    };
    

    【讨论】:

    • mAsyncRunner.request("me/feed", params, "POST");此方法在 AsyncFacebookRunner 中不可用。您使用的是哪个 SDK,请提供链接。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-02
    • 1970-01-01
    相关资源
    最近更新 更多