如何使用此基本代码获得 Facebook 许可:
Session.openActiveSession(this, true, new Session.StatusCallback() {
// callback when session changes state
@Override
public void call(Session session, SessionState state, Exception exception) {
Log.d("call", "Called : " + state.toString());
if (session.isOpened()) {
Log.d("session.isOpened()", "Called");
// 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) {
Log.d("onCompleted", "Called");
if (user != null) {
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
}
}
请用这段代码告诉我如何添加权限。
我看到了这段代码:
private static Session
openActiveSession(Activity activity, boolean allowLoginUI, StatusCallback callback, List<String> permissions)
{
Log.d("openActiveSession","called");
OpenRequest openRequest = new OpenRequest(activity).setPermissions(permissions).setCallback(callback);
Session session = new Builder(activity).build();
if (SessionState.CREATED_TOKEN_LOADED.equals(session.getState()) || allowLoginUI) {
Session.setActiveSession(session);
session.openForRead(openRequest);
return session;
}
return null;
}
但我不知道这是否是最简单的方法,或者如何以及何时实施。