- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在关注 facebook 入门指南 https://developers.facebook.com/docs/android/getting-started 但页面上给出的代码不起作用 Session.openActiveSession(this, true, new Session.StatusCallback() 不起作用
包com.example.testapp;
import com.facebook.Request;
import com.facebook.Response;
import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.model.GraphUser;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("FB","pass 0");
Session.openActiveSession(this, true, new Session.StatusCallback(){
@SuppressWarnings("deprecation")
@Override
public void call(Session session, SessionState state,
Exception exception) {
// TODO Auto-generated method stub
if (session.isOpened()) {
Log.d("FB","pass 1");
// 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) {
// TODO Auto-generated method stub
if (user != null) {
Log.d("FB","pass");
TextView welcome = (TextView) findViewById(R.id.textView1);
welcome.setText("Hello " + user.getName() + "!");
}
}
});
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
}
最佳答案
SessionTracker mSessionTracker = new SessionTracker(getBaseContext(),
new StatusCallback() {
public void call(Session session, SessionState state,
Exception exception) {
}
}, null, false);
String applicationId = Utility
.getMetadataApplicationId(getBaseContext());
mCurrentSession = mSessionTracker.getSession();
if (mCurrentSession == null || mCurrentSession.getState().isClosed()) {
mSessionTracker.setSession(null);
Session session = new Session.Builder(getBaseContext())
.setApplicationId(applicationId).build();
Session.setActiveSession(session);
mCurrentSession = session;
}
Log.d("session in login", mCurrentSession + "");
if (!mCurrentSession.isOpened()) {
Session.OpenRequest openRequest = null;
openRequest = new Session.OpenRequest(LoginActivity.this);
if (openRequest != null) {
openRequest.setDefaultAudience(SessionDefaultAudience.FRIENDS);
openRequest.setPermissions(Arrays.asList("email"));
openRequest
.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);
mCurrentSession.openForRead(openRequest);
Log.e("session closed","session closed");
}
} else {
Request.executeMeRequestAsync(mCurrentSession,
new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user,
Response response) {
Log.e("san<><><>",
user.getId() + " " + user.getName() + " "
+ user.getInnerJSONObject() + ""
+ user.asMap().get("email"));
}
});
}
试试这个
关于java - Facebook Session.openActiveSession(this, true, new Session.StatusCallback() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21372464/
我第一次可以正常登录。我有一个选项,用户可以在 android 应用程序中禁用 facebook。选择此选项后,facebook 状态将变为已关闭。当我再次使用该选项时,重新登录 API 在回调函数内
我正在关注 facebook 入门指南 https://developers.facebook.com/docs/android/getting-started 但页面上给出的代码不起作用 Sessi
我正在尝试使用 Facebook Android SDK 登录 Facebook,但是,状态回调仅在 OPENING session 状态下触发一次。在那之后,一个没有内容的 Facebook 登录
我正在使用 3.1 Facebook SDK 和在“设置”中设置的 iOS 6 Facebook,并且我的应用已获得授权。 这完美执行: [FBSession openActiveSessionWit
我正在测试新的 3.1 框架。如果我调用 [FBSession openActiveSessionWithReadPermissions:allowLoginUI:completionHandler
我是一名优秀的程序员,十分优秀!