0

我正在尝试使用 facebook SDK 提交一个简单的发布请求。这是代码:

public void ShareLinkOnFacebook()
    {
        Facebook mFacebook = ((GlobalVars)getApplicationContext()).facebook;
         AsyncFacebookRunner mAsyncFbRunner = new AsyncFacebookRunner(mFacebook);
         Bundle params = new Bundle();
         params.putString("message",  place.name );
         params.putString("link", "http://www.facebook.com");
         mAsyncFbRunner.request("me/feed", params, "POST", new RequestListener());
    }

但我有编译错误说RequestListener无法解析为类型。我该怎么做才能让它工作?

4

2 回答 2

0

请检查此侦听器。

   public void postOnWall(String msg) {
        Log.d("Tests", "Testing graph API wall post");
         try {
                String response = mFacebook.request("me");
                Bundle parameters = new Bundle();
                parameters.putString("message", msg);
                parameters.putString("description", "test test test");
                response = mFacebook.request("me/feed", parameters, 
                        "POST");
                Log.d("Tests", "got response: " + response);
                if (response == null || response.equals("") || 
                        response.equals("false")) {
                   Log.v("Error", "Blank response");
                }
         } catch(Exception e) {
             e.printStackTrace();
         }
    }
于 2012-11-03T11:18:11.823 回答
0

试试这个这是我的工作代码:-在wallpost按钮上单击:-

 mPostButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mFacebook.dialog(Class.this, "feed",
                    new SampleDialogListener());
        }

&

      public class SampleDialogListener extends BaseDialogListener {

    public void onComplete(Bundle values) {
        final String postId = values.getString("post_id");
        if (postId != null) {
            Log.d("Facebook-Example", "Dialog Success! post_id=" + postId);
            mAsyncRunner.request(postId, new WallPostRequestListener());

            mDeleteButton.setVisibility(View.VISIBLE);
        } else {
            Log.d("Facebook-Example", "No wall post made");
        }
    }
}

& BaseDialogListner:---

    public abstract class BaseDialogListener implements DialogListener {

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

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

public void onCancel() {
}

}

  public class WallPostRequestListener extends BaseRequestListener {

    public void onComplete(final String response, final Object state) {
        Log.d("Facebook-Example", "Got response: " + response);
        String message = "<empty>";
        try {
            JSONObject json = Util.parseJson(response);
            message = json.getString("message");
        } catch (JSONException e) {
            Log.w("Facebook-Example", "JSON Error in response");
        } catch (FacebookError e) {
            Log.w("Facebook-Example", "Facebook Error: " + e.getMessage());
        }
        final String text = "Your Wall Post: " + message;
        VideoUpload.this.runOnUiThread(new Runnable() {
            public void run() {
                mText.setText(text);
            }
        });
    }
}

& BaseRequestListner:--

  public abstract class BaseRequestListener implements RequestListener {

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

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

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

public void onMalformedURLException(MalformedURLException e,
        final Object state) {
    Log.e("Facebook", e.getMessage());
    e.printStackTrace();
}
于 2012-11-03T13:14:32.490 回答