当前位置: 动力学知识库 > 问答 > 编程问答 >

facebook - Unable to import Session,Request,Response,GraphUser packages in android

问题描述:

I imported latest facebook sdk in my ecllipe.When i am trying to get basic information in my app,it does n't import respective packages of Request,Response,and Session.what i do?to import respective packages.

I tried below code but facing problem at importing respective packages.

LoginActivity.java

 @Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

if (Session.getActiveSession() == null

|| Session.getActiveSession().isClosed()) {

Session.openActiveSession(this, true, new StatusCallback() {

@Override

public void call(Session session, SessionState state,

Exception exception) {

System.out.println("State= " + state);

if (session.isOpened()) {

System.out.println("Token=" + session.getAccessToken());

Request.executeMeRequestAsync(session,

new GraphUserCallback() {

@Override

public void onCompleted(GraphUser user,

Response response) {

if (user != null) {

System.out.println("User=" + user);

}

if (response != null) {

System.out.println("Response="

+ response);

Toast.makeText(MainActivity.this,

response.toString(),

Toast.LENGTH_LONG).show();

}

}

});

}

if (exception != null) {

System.out.println("Some thing bad happened!");

exception.printStackTrace();

}

}

});

}

}

@Override

public void onActivityResult(int requestCode, int resultCode, Intent data) {

super.onActivityResult(requestCode, resultCode, data);

Session.getActiveSession().onActivityResult(this, requestCode,

resultCode, data);

}

网友答案:

It happens with you because session is removed from new android SDK 4. So you cant not use this code for getting user information.

Try to use this code. It's work successfully for me.

First Initialize FacebookSdk in onCreate before inflecting layout.

FacebookSdk.sdkInitialize(this.getApplicationContext());
分享给朋友:
您可能感兴趣的文章:
随机阅读: