请问Facebook的SDK只与活动的工作? [英] Does the Facebook SDK only work with Activities?

查看:194
本文介绍了请问Facebook的SDK只与活动的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图实现Facebook SDK到我的应用程序,以便让用户通过应用程序发布在我们的fanwall消息。不过,我已经成功在即使在通过SDK注销用户。

I've been trying to implement the Facebook SDK into my application in order to let users post messages on our fanwall through the app. However, I've been unsuccessful at even logging the user in through the SDK.

在SDK中的例子,一个简单的示例已经给它使用一个活动来尝试并使用单点登录授权用户。我试过这个例子我自己,和它的作品。我能登录,我不得不批准该应用使用我的Facebook的数据,我可以看到所取得的请求,并在收到LogCat中

In the SDK examples, a simple sample has been given which uses an Activity to try and authorize the user using Single Sign-On. I've tried this example myself, and it works. I'm able to log in, I had to authorize the app to use my Facebook data and I could see the requests being made and received in LogCat.

现在,我已经尝试添加相同code到自己的应用程序。使用兼容包这个程序是片段为主。有一个中心 FragmentActivity 和我的班,其余都是简单的片段。当添加样品code到其中的一个片段,Facebook应用程序半秒试图授权时启动,但后来关闭,什么都没有发生。我回到了我的正常片段一次。

Now, I've tried adding the same code to my own app. This app is Fragment based using the Compatibility package. There is one central FragmentActivity and the rest of my classes are simple Fragments. When adding the sample code to one of these Fragments, the Facebook app starts up for half a second when trying to authorize, but afterwards closes and nothing has happened. I'm back in my regular Fragment again.

在经过检查这个LogCat中,没有迹象表明Facebook应用程序甚至打开或做得比它显示了一些印刷检查我补充,它说,它的开始Facebook的意图其实事实以外的任何请求:

When checking the LogCat after this, nothing suggests that the Facebook app even opened or made any requests other than the fact it shows some printing checks I added and the fact it says it's starting the Facebook intent :

01-12 13:19:40.874: I/System.out(6087): Calling authorize
01-12 13:19:40.874: I/ActivityManager(1380): Starting activity: Intent { cmp=com.facebook.katana/.ProxyAuth (has extras) } from pid 6087
01-12 13:19:40.874: I/System.out(6087): Called authorize

除此之外,没有东西返回。没有的Facebook的检查,不声明说我的钥匙是错误的东西,只会什么都得不到。 Facebook的意图是所谓的,但几乎立即关闭,没有别的,显示这是连开。

Other than that, nothing gets returned. No Facebook-checks, no statements saying my keys are wrong or anything, just nothing. The Facebook intent was called, but closed almost immediately and nothing else shows that it was even open.

本已令人难以置信我的脑海里了几个小时,现在,我开始觉得正规,样品提供的方式只是没有在片段由于工作的方式片段工作

This has been boggling my mind for a few hours now, and I'm starting to think the regular , sample-provided approach just doesn't work in Fragments due to the way Fragments work.

我一直在使用code如下公布。该片段得到由一个按钮,调用 FragmentTransaction 解雇。我在做某种根本性错误在这里,还是Facebook的SDK真的只是不能与片段工作?我试图寻找这个问题,但我一直没能找到任何人有相同的排序情况。

The code I've been using is posted below. The Fragment gets fired by a button which calls a FragmentTransaction. Am I doing something fundamentally wrong here, or does the Facebook SDK really just not work with Fragments? I've tried searching for this problem but I haven't been able to find anyone else with the same sort of situation.

public class FanWallFacebook extends Fragment {

    Facebook facebook = new Facebook("294678133912628");

    public FanWallFacebook() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.filler, container, false);
    }

    @Override
    public void onStart() {
        super.onStart();

        System.out.println("Calling authorize");
        facebook.authorize(getActivity(), new DialogListener() {
            @Override
            public void onComplete(Bundle values) {
                System.out.println("Completed");
            }

            @Override
            public void onFacebookError(FacebookError error) {
                System.out.println("Facebook error: "+error.getMessage());
            }


            @Override
            public void onError(DialogError e) {
                System.out.println("General error: "+e.getMessage());
            }

            @Override
            public void onCancel() {
                System.out.println("Cancelled");
            }
        });

        System.out.println("Called authorize");

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        facebook.authorizeCallback(requestCode, resultCode, data);
        System.out.println("Authorize callback'd");
    }

}


修改

使用 FragmentActivity ,看哪刚试过你看,这确实工作。它成功登录。好像真的SDK只明确延长 ...活动类的作品。谁能给我一个想法,为什么这可能是这样?我一直以为片段某处延长线活动以及

Just tried using a FragmentActivity, and lo and behold, that does work. It successfully logs in. Seems like the SDK really only works with classes that explicitly extend ...Activity. Could anyone give me an idea why that might be the case? I always thought Fragments somewhere down the line extended Activity as well.

推荐答案

我结束了使用 FragmentActivity 我的Facebook的互动。没有理想的解决方案,但它工作。

I ended up using a FragmentActivity for my Facebook interaction. Not the ideal solution, but it works.

这篇关于请问Facebook的SDK只与活动的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆