在Android应用程序中创建facebook事件

概述我是 android的新手,我只想从我要开发的应用程序创建一个Facebook事件.稍后我会添加邀请朋友的功能. 我想以通知或任何好的方式显示邀请. 我在互联网上做了很多研究,但找不到解决方案. 我真的很感激任何解决方案…… 谢谢! package com.tharaka.facebook;import java.io.FileNotFoundException;import java.i 我是 android的新手,我只想从我要开发的应用程序中创建一个Facebook事件.稍后我会添加邀请朋友的功能.
我想以通知或任何好的方式显示邀请.

我在互联网上做了很多研究,但找不到解决方案.

我真的很感激任何解决方案……

谢谢!

解决方法
package com.tharaka.facebook;import java.io.fileNotFoundException;import java.io.IOException;import java.net.MalformedURLException;import org.Json.JsONException;import org.Json.JsONObject;import androID.app.Activity;import androID.content.SharedPreferences;import androID.os.Bundle;import androID.util.Log;import androID.vIEw.Menu;import androID.vIEw.VIEw;import androID.vIEw.VIEw.OnClickListener;import androID.Widget.button;import androID.Widget.Toast;import com.facebook.androID.AsyncFacebookRunner;import com.facebook.androID.AsyncFacebookRunner.RequestListener;import com.facebook.androID.DialogError;import com.facebook.androID.Facebook;import com.facebook.androID.Facebook.DialogListener;import com.facebook.androID.FacebookError;import com.tharaka.facebook.R;public class MainActivity extends Activity implements OnClickListener{    // Your Facebook APP ID    private static String APP_ID = "392736034134808"; // Replace your App ID                                                      // here    // Instance of Facebook Class    private Facebook facebook;    private AsyncFacebookRunner mAsyncRunner;    String filename = "AndroIDSSO_data";    private SharedPreferences mPrefs;    private button btnFbLogin;    private button btnCreateEvent;    private String TAG="MainActivity";    @OverrIDe    protected voID onCreate(Bundle savedInstanceState)    {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main);        initialize();        setListeners();    }    private voID initialize()    {        facebook = new Facebook(APP_ID);        mAsyncRunner = new AsyncFacebookRunner(facebook);        btnFbLogin = (button) findVIEwByID(R.ID.button_FbLogin);        btnCreateEvent = (button) findVIEwByID(R.ID.button_createEvent);    }    private voID setListeners()    {        btnFbLogin.setonClickListener(this);        btnCreateEvent.setonClickListener(this);    }    @OverrIDe    public boolean onCreateOptionsMenu(Menu menu)    {        // Inflate the menu; this adds items to the action bar if it is present.        getMenuInflater().inflate(R.menu.activity_main,menu);        return true;    }    @OverrIDe    public voID onClick(VIEw vIEw)    {        switch (vIEw.getID())        {            case R.ID.button_FbLogin:                loginToFacebook();                break;                        case R.ID.button_createEvent:                createEvent();                Toast.makeText(getApplicationContext(),"New Event Created!!",Toast.LENGTH_LONG).show();                break;            default:                break;        }    }    private voID loginToFacebook()    {        mPrefs = getPreferences(MODE_PRIVATE);        String access_token = mPrefs.getString("access_token",null);        long expires = mPrefs.getLong("access_expires",0);        if (access_token != null)        {            facebook.setAccesstoken(access_token);        }        if (expires != 0)        {            facebook.setAccessExpires(expires);        }        if (!facebook.isSessionValID())        {            facebook.authorize(this,new String[] {                "email","publish_stream","create_event"            },new DialogListener()            {                @OverrIDe                public voID onCancel()                {                    // Function to handle cancel event                }                @OverrIDe                public voID onComplete(Bundle values)                {                    // Function to handle complete event                    // Edit Preferences and update facebook acess_token                    SharedPreferences.Editor editor = mPrefs.edit();                    editor.putString("access_token",facebook.getAccesstoken());                    editor.putLong("access_expires",facebook.getAccessExpires());                    editor.commit();                }                @OverrIDe                public voID onError(DialogError error)                {                    // Function to handle error                }                @OverrIDe                public voID onFacebookError(FacebookError fberror)                {                    // Function to handle Facebook errors                }            });        }    }    private voID createEvent()    {        try        {            Bundle params = new Bundle();            params.putString("name","This is a test event");            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 yeah?.");            params.putString("location","Mount Lavinia");            //params.putString("location_ID","");            params.putString("privacy_type","OPEN");            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);                        String event_ID = event.getString("ID");                        Log.i(TAG,"Event ID => "+event_ID);                       //Toast.makeText(getApplicationContext(),Toast.LENGTH_LONG).show();                    }                    catch (Exception e)                    {                    }                }            },null);        }        catch (Exception e)        {        }    }}
总结

以上是内存溢出为你收集整理的在Android应用程序中创建facebook事件全部内容,希望文章能够帮你解决在Android应用程序中创建facebook事件所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1126786.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存