gpt4 book ai didi

java - Facebook Session.openActiveSession(this, true, new Session.StatusCallback() 不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 15:10:37 24 4
gpt4 key购买 nike

我正在关注 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com