[英]Android log in app using Facebook
Please anyone can tell me why this code do not return the result? 请有人告诉我为什么这段代码不会返回结果? It always stops in
它总是停下来
( if is.open())
and gives false. 并给出错误。
com.facebook.Session.openActiveSession(this, true, new com.facebook.Session.StatusCallback() {
@Override
public void call(com.facebook.Session session, SessionState state,
Exception exception) {
// TODO Auto-generated method stub
if (session.isOpened()) {
// make request to the /me API
Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
// callback after Graph API response with user object
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
TextView welcome = (TextView) findViewById(com.example.connectwithfacebook.R.id.textView1);
welcome.setText("Hello " + user.getName() + "!");
}
}
});
}
}
});
I implemented another way but I had then the same problem too. 我实现了另一种方式,但我也遇到了同样的问题。
It has to do with your hashkey within facebook. 它与facebook中的hashkey有关。 Run this code (make sure to change package name in 3rd line):
运行此代码(确保在第3行更改包名称):
try {
PackageInfo info = getPackageManager().getPackageInfo(
"your.root.package",
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
It will output the signature as "KeyHash:XXXXX" into logcat. 它会将签名“KeyHash:XXXXX”输出到logcat中。 Copy and paste that key into facebook and wil should start working.
将该密钥复制并粘贴到facebook中,并且应该开始工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.