1

以下是我为创建 facebook 事件所做的代码,但是此代码不起作用,没有编译或运行时错误。我已经编写了方法并在按钮单击事件上调用了该方法。

public class createEvent extends Activity implements OnClickListener

{
    private Button btnCreateEven;
    private TextView txteventName;
    private AsyncFacebookRunner mAsyncRunner;
    private String eventID="";
    private Facebook facebookatEventCreate;
    private String eventName = "";
    private SharedPreferences mPrefs;
    private static String appId = "392736034134808";



        @Override
        protected void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.create_event);
            //problem - unable to start activity when setListeners() is uncommented 
           initialize(); 
           setListeners();
        }




        private void initialize()
        {            
            //facebook = new Facebook(APP_ID);
            facebookatEventCreate = new Facebook(appId);
            mAsyncRunner = new AsyncFacebookRunner(facebookatEventCreate);
            btnCreateEven = (Button) findViewById(R.id.btn_createEvent);
            txteventName = (TextView)findViewById(R.id.txt_eventName);
        }


        private void setListeners()
        {

            btnCreateEven.setOnClickListener(this);

        }




        @Override
        public void onClick(View v)
        {
            switch (v.getId())
            {
                case R.id.btn_createEvent:
                    createEvents();
                default:
                    break;
            }

        }



        /**
         * Creates a new event.
         * 
         * 
         * 
         */

        private void createEvents()
        {
            try
            {                   


                Bundle params = new Bundle();
                params.putString("name", "test test test");
                params.putString("start_time", "2013-12-02T18:00:00+0530");
                params.putString("end_time", "2013-12-02T20:00:00+0530");
                params.putString("description", "This is test description 10/12/2012");
                params.putString("location", "Mount Lavinia");
                //params.putString("location_id", "");
                params.putString("privacy_type", "OPEN");
                params.putString("picture", "/sdcard/cmd.png");
                mAsyncRunner.request("me/events", params, "POST", new RequestListener()
                {

                    @Override
                    public void onMalformedURLException(MalformedURLException e, Object state)
                    {

                    }

                    @Override
                    public void onIOException(IOException e, Object state)
                    {

                    }

                    @Override
                    public void onFileNotFoundException(FileNotFoundException e, Object state)
                    {

                    }

                    @Override
                    public void onFacebookError(FacebookError e, Object state)
                    {

                    }

                    @Override
                    public void onComplete(String response, Object state)
                    {
                        try
                        {
                            JSONObject event = new JSONObject(response);
                            eventID = event.getString("id");
                            Log.d("createEvent:createEvent", "Event ID->" + eventID);

                           //Toast.makeText(getApplicationContext(), "New Event Created!!", Toast.LENGTH_LONG).show();
                        }
                        catch (Exception e)
                        {

                        }
                    }
                }, null);
            }
            catch (Exception e)
            {

            }
        }





}

请告诉我这是什么原因,欢迎评论!

4

1 回答 1

0

我没有看到您在任何地方对用户进行身份验证。您可以在此处阅读有关如何执行此操作的信息:Android 的 Facebook 身份验证

如果您已经对用户进行了身份验证,则需要在创建新 Facebook 对象时保存身份验证令牌。您可以使用以下方法读取访问令牌:

facebookatEventCreate.setAccessToken(authToken);
facebookatEventCreate.setAccessExpires(unixTime);
于 2012-12-10T08:02:00.910 回答