新的Facebook API 3.0。和ActionBarSherlock兼容性兼容性、API、Facebook、ActionBarSherlock

2023-09-05 00:32:55 作者:怪味萌友

我读的Facebook的Andr​​oid 3.0的API文档,我不明白什么呢会议,是因为有后台活动。在所有的例子我应该延长FacebookFragment。那么,这将是很好,如果我的整个程序是不扩展SherlockFragment所以我不认为延长FacebookFragment作为一个选项。

I'm reading facebook Android API 3.0 documents, and I do not understand what does session has to do with background activities. In all examples I'm supposed to extend "FacebookFragment". Well, that would be nice if my whole app is not extending "SherlockFragment" so I do not see extending FacebookFragment as an option.

如果我使用code从SessionLoginExample,并把我的AppID的字符串作为Facebook并我得到了同样的字符串:

If I use the code from SessionLoginExample, and put my AppID in Strings in the very same string as facebook does I get the:

错误

10-22 17:04:26.464: E/AndroidRuntime(5491): FATAL EXCEPTION: main
10-22 17:04:26.464: E/AndroidRuntime(5491): java.lang.RuntimeException: Unable to start activity ComponentInfo{nl.specsavers.moodspecs/nl.specsavers.moodspecs.LauncherActivity}: java.lang.NullPointerException: Argument applicationId cannot be null

我想如果已安装的应用程序来设置初始检查与否,如果会话存在与否。

I'm trying to set up the initial check if the app is installed or not, and if session exists or not.

 Settings.addLoggingBehavior(LoggingBehaviors.INCLUDE_ACCESS_TOKENS);

    Session session = Session.getActiveSession();
    if (session == null) {
        if (savedInstanceState != null) {
            session = Session.restoreSession(this, null, statusCallback, savedInstanceState);
        }
        if (session == null) {
            session = new Session(this);
        }
        Session.setActiveSession(session);
        if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
            session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
        }

    } 

我需要能够以某种方式把我的应用程序ID的地方,它实际上是正常的,但我找不到在哪里把它。

I need to be able to somehow put my App ID somewhere that it is actually OK, but I can't find where to put it.

我需要知道,如果我能避免延长FacebookFragment因为我用SherlockFragment。

I need to know If I can avoid extending FacebookFragment as I use SherlockFragment.

TNX。

推荐答案

FacebookFragment是不公开的,而不是用于应用程序使用。

FacebookFragment is not public and is not intended for use by applications.

样品也大多使用FacebookActivity不过,是的 - 你的不可以需要延长FacebookActivity。正如你提到的,SessionLoginSample说明了这一点,如果你不使用FacebookActivity你应该处理会话序列化,并覆盖/前进onActivityResult如图那里。

The samples do mostly use FacebookActivity though, and yes--you do not need to extend FacebookActivity. As you mention, SessionLoginSample demonstrates this, and if you are not using FacebookActivity you should handle Session serialization and override/forward onActivityResult as illustrated there.

不过,这听起来像你打的周围设置的applicationID的主要问题。您可以在code或元数据集的applicationID。

That said, it sounds like the main issue you are hitting is around setting the applicationId. You can set applicationId in code or in meta-data.

要设置在code,定义一个字符串常量MY_APP_ID包含您的应用程序ID和替换该行:

To set it in code, define a String constant MY_APP_ID that contains your app id and replace the line:

session = new Session(this);

session = new Session.Builder(this).setApplicationId(MY_APP_ID).build();

在元数据:

要设置它的元数据,以下内容添加到您的Andr​​oidManifest.xml任何活动标签应用标签内,但外:

In metadata:

To set it in meta-data, add the following to your AndroidManifest.xml inside the application tag but outside of any activity tags:

<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>

然后,在价值/ strings.xml中,对于APP_ID添加值,有你的应用程序ID:

Then, in values/strings.xml, add a value for app_id that has your app id:

<string name="app_id">1234567890</string>