通过Android的Facebook登录 [英] Facebook login through android

查看:188
本文介绍了通过Android的Facebook登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个Android应用程序集成的Facebook,但在登录Facebook的一步失败。我在做什么基本上是执行授权,然后问,如果会话有效。的答案总是否定的。如果我试图像一个简单的要求:

 字符串响应= facebookClient.request(我);

我得到这个答复:


  

{错误:{消息:一个活性访问令牌必须用来查询
  关于当前用户的信息,类型:OAuthException}}


也许我有错误的散列键(通过我读pretty好线程如何得到它的权利)。我想知道这是确保关键是匹配的一种方式。

我根据我的code这个 - <一个href=\"http://stackoverflow.com/questions/2953146/android-java-post-simple-text-to-facebook-wall/2956352#2956352\">Android/Java - 发布简单的文本给Facebook墙,并添加一些细微的变化?这是code:

 公共类FacebookActivity扩展活动实现DialogListener
{    私人facebook facebookClient;    @覆盖
    保护无效的onCreate(捆绑savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.main); //我的布局XML    }    公共无效登录(查看视图)
    {
            facebookClient =新的Facebook(我的应用程序ID);
            facebookClient.authorize(这一点,这一点);
            如果(facebookClient.isSessionValid()==真)
                Log.d(有效,是);
            其他
                Log.d(有效,无);
    }
}


解决方案

请注意,授权方法是异步的。

您应该实现DialogListener的方法的onComplete,让所有你需要的工作(如图形API请求我)那里。

I write an Android application that integrates facebook, but failing in the login to facebook step. What I'm doing basically is to perform authorization and then ask if the session is valid. The answer is always negative. If I'm trying a simple request like:

 String response = facebookClient.request("me"); 

I am getting this response:

{"error":{"message":"An active access token must be used to query information about the current user.","type":"OAuthException"}}

Maybe I have the wrong hash key (through I read pretty good threads how to get it right). I'd like to know if this is a way to insure key is matching.

I based my code on this - Android/Java -- Post simple text to Facebook wall?, and add some minor changes. This is the code:

public class FacebookActivity extends Activity implements DialogListener
{

    private Facebook facebookClient;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.main);//my layout xml  

    }



    public void login(View view)
    {
            facebookClient = new Facebook("my APP ID");
            facebookClient.authorize(this, this);
            if (facebookClient.isSessionValid() == true)
                Log.d("Valid:", "yes");
            else
                Log.d("Valid:", "no");
    }
}

解决方案

Note that authorize method is asynchronous.

You should implement an onComplete method of DialogListener and make all the work you need (such as graph API me request) there.

这篇关于通过Android的Facebook登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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