0

我已经在 Android 中使用 Facebook 创建了邀请用户到应用程序,为此使用了 Facebook SDK 并添加了人们给出的代码,这是我的代码

 final ImageView facebook1 = (ImageView) findViewById(R.id.facebook1);
        facebook1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v){
           // Perform action on click
            Facebook facebook1 = new Facebook("APP_ID");



            Bundle paramsOut = new Bundle(), paramsIn = this.getIntent().getExtras();
            paramsOut.putString("message", paramsIn.getString("message"));
            Singlemenuitem.this.mFacebook.dialog(this, "apprequests", paramsOut, new InviteListener(this));
            mFacebook.dialog(Singlemenuitem.this, "apprequests", params, new DialogListener() {

                public void onComplete(Bundle values) {
                    final String returnId = values.getString("request");

                    if (returnId != null) {
                        Toast.makeText(getApplicationContext(),
                                       "Request sent " + returnId,
                                       Toast.LENGTH_SHORT).show();
                    }
                }
                public void onFacebookError(FacebookError error) {}

                public void onError(DialogError e) {}

                public void onCancel() {}
            });
        }

但是代替“InviteListener”创建类时出错,如果创建了类,那么也会出错。有什么指导吗?

4

1 回答 1

0
Bundle iviteBundleparams = new Bundle();
        iviteBundleparams.putString("message",
                "invite message");

//TODO:// if you have friend id then you can pass friend id and the request will send this particular friend id
//myIviteBundleparams.putString("to",
                                    friendId);
final ImageView facebook1 = (ImageView) findViewById(R.id.facebook1);
    facebook1.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                try {


                            mFacebook.dialog(context,
                                    "apprequests", iviteBundleparams,
                                    new AppRequestsListener());
                        } 


                } catch (Exception e) {
                    // Log.e("VIAMO_FRIENDS", "" + e.toString());
                    e.printStackTrace();
                }

            }
        });





/*
     * callback for the apprequests dialog which sends an app request to user's
     * friends.
     */
    public class AppRequestsListener extends BaseDialogListener {


        /* Default constructor definition */
        public AppRequestsListener() {
            // TODO Auto-generated constructor stub
        }

        public void onComplete(Bundle values) {
            if (values.size() < 1) {
                Toast toast = Toast.makeText(getApplicationContext(),
                        "App request cancelled", Toast.LENGTH_SHORT);
                toast.show();
            } else {
                Toast toast = Toast.makeText(getApplicationContext(),
                        "App request sent", Toast.LENGTH_LONG);
                toast.show();


            }
        }

        public void onFacebookError(FacebookError error) {
            Toast.makeText(getApplicationContext(),
                    "Facebook Error: " + error.getMessage(), Toast.LENGTH_SHORT)
                    .show();
        }

        public void onCancel() {
            Toast toast = Toast.makeText(getApplicationContext(),
                    "App request cancelled", Toast.LENGTH_SHORT);
            toast.show();
        }
    }

//这里 mFacebook 是你的 Facebook 对象 //Facebook mFacebook = new Facebook(APP_ID);

于 2013-01-03T13:46:03.280 回答