在我的应用程序中,我正在尝试连接 facebook。登录后如果有权限会询问是否允许,也可以贴墙。
同一个应用程序在模拟器上可以正常工作,但在手机登录窗口和允许权限窗口不会出现。 为什么会这样?
在我的登录代码下方,
public class LoginListener implements DialogListener {
@Override
public void onComplete(Bundle values) {
if (testAuthenticatedApi())
System.out.println("Login successfully...");
if (testAuthenticatedErrors()) {
System.out.println("Login successfully...");
}
}
}
public boolean testAuthenticatedApi() {
if (!facebook.isSessionValid())
return false;
try {
Log.d("Tests", "Testing request for 'me'");
String response = facebook.request("me");
JSONObject obj = Util.parseJson(response);
if (obj.getString("name") == null ||
obj.getString("name").equals("")) {
return false;
}
Log.d("Tests", "Testing graph API wall post");
Bundle parameters = new Bundle();
parameters.putString("message", "hello world");
parameters.putString("description", "test test test");
response = facebook.request("me/feed", parameters,
"POST");
Log.d("Tests", "got response: " + response);
if (response == null || response.equals("") ||
response.equals("false")) {
return false;
}
Log.d("Tests", "Testing graph API delete");
response = response.replaceAll("\\{\"id\":\"", "");
response = response.replaceAll("\"\\}", "");
response = facebook.request(response, new Bundle(),
"DELETE");
if (!response.equals("true")) return false;
Log.d("Tests", "Testing old API wall post");
parameters = new Bundle();
parameters.putString("method", "stream.publish");
parameters.putString("attachment",
"{\"name\":\"Name=Title\"," +
"\"href\":\"http://www.google.fr/\",\"" +
"caption\":\"Caption\",\"description\":\"Description" +
"\",\"media\":[{\"type\":\"image\",\"src\":" +
"\"http://www.kratiroff.com/logo-facebook.jpg\"," +
"\"href\":\"http://developers.facebook.com/\"}]," +
"\"properties\":{\"another link\":{\"text\":\"" +
"Facebook homepage\",\"href\":\"http://www.facebook." +
"com\"}}}");;
response = facebook.request(parameters);
Log.d("Tests", "got response: " + response);
if (response == null || response.equals("") ||
response.equals("false")) {
return false;
}
Log.d("Tests", "Testing wall post delete");
response = response.replaceAll("\"", "");
response = facebook.request(
response, new Bundle(), "DELETE");
if (!response.equals("true")) return false;
Log.d("Tests", "All Authenticated Tests Passed");
return true;
} catch (Throwable e) {
e.printStackTrace();
return false;
}
}
public boolean testAuthenticatedErrors() {
if (!facebook.isSessionValid()) return false;
Log.d("Tests", "Testing that request for 'me/invalid' is rejected");
try {
Util.parseJson(facebook.request("me/invalid"));
return false;
} catch (Throwable e) {
Log.d("Tests", "*" + e.getMessage() + "*");
if (!e.getMessage().equals("Unknown path components: /invalid")) {
return false;
}
}
Log.d("Tests", "Testing that old API call with invalid method fails");
Bundle params = new Bundle();
params.putString("method", "something_invalid");
try {
Util.parseJson(facebook.request(params));
return false;
} catch (Throwable e) {
Log.d("Tests", "*" + e.getMessage() + "*");
if (!e.getMessage().equals("Unknown method") ) {
return false;
}
}
Log.d("Tests", "All Authenticated Error Tests Passed");
return true;
}
最佳答案
问题可能出在登录的 SSO(单点登录)功能上。
以下链接可能会有帮助。
facebook login dialog disappears soon after loading
http://ukgupta.blogspot.com/2011/07/facebook-implementation-into-android.html
关于android手机打开facebook允许权限窗口的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7346704/