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

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

问题描述

我写了一个集成了Facebook的Android应用程序,但是登录到Facebook的步骤失败。我所做的基本上是执行授权,然后询问会话是否有效。答案总是否定的。如果我正在尝试一个简单的请求:

  String response = facebookClient.request(me); 

我收到此回复:


{error:{message:必须使用活动的访问令牌查询当前用户的
信息。,type:OAuthException}} p>

也许我有错误的哈希键(通过我阅读不错的线程如何正确)。我想知道这是否是确保密钥匹配的一种方式。



我基于我的代码 - Android / Java - 发布简单的文本到Facebook墙?,并添加一些小的更改。这是代码:

  public class FacebookActivity extends Activity implements DialogListener 
{

private Facebook Facebook客户端

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

}



public void login(View查看)
{
facebookClient =新Facebook(我的APP ID);
facebookClient.authorize(this,this);
if(facebookClient.isSessionValid()== true)
Log.d(Valid:,yes);
else
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.

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

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