我正在检索Facebook的朋友;你能建议如何从给定的代码中检索Facebook。我是android的新手。所以请帮我这个。我没有从Facebook SDK获得适当的指导。
代码如下所示。
朋友申请
import java.util.Arrays;
import java.util.List;
import com.facebook.Session;
import com.facebook.Request;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.facebook.HttpMethod;
import com.facebook.Response;
import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.UiLifecycleHelper;
import com.facebook.model.GraphUser;
import com.facebook.widget.LoginButton;
import com.facebook.widget.LoginButton.UserInfoChangedCallback;
public class MainActivity extends FragmentActivity {
private LoginButton loginBtn;
private UiLifecycleHelper uiHelper;
private ListView friendList;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
uiHelper = new UiLifecycleHelper(this, statusCallback);
uiHelper.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
friendList = (ListView) findViewById(R.id.friends_list);
loginBtn = (LoginButton) findViewById(R.id.fb_login_button);
loginBtn.setReadPermissions(Arrays.asList("email"));
loginBtn.setReadPermissions(Arrays.asList("user_friends"));
// final Session session = Session.getActiveSession();
loginBtn.setUserInfoChangedCallback(new UserInfoChangedCallback() {
@Override
public void onUserInfoFetched(GraphUser user) {
if (user != null) {
// new Request(
// Session.getActiveSession(),
// "/me/friends",
// null,
// HttpMethod.GET,
// new Request.Callback() {
// public void onCompleted(Response response) {
// System.out.println("RESPONSE :- " + response.toString());
// Log.i("DJ", "response; " + response.toString());
// }
// }).executeAsync();
} else {
}
}
});
}
private Session.StatusCallback statusCallback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state,
Exception exception) {
if (state.isOpened()) {
Log.d("MainActivity", "Facebook session opened.");
} else if (state.isClosed()) {
Log.d("MainActivity", "Facebook session closed.");
}
}
};
@Override
public void onResume() {
super.onResume();
uiHelper.onResume();
}
@Override
public void onPause() {
super.onPause();
uiHelper.onPause();
}
@Override
public void onDestroy() {
super.onDestroy();
uiHelper.onDestroy();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onSaveInstanceState(Bundle savedState) {
super.onSaveInstanceState(savedState);
uiHelper.onSaveInstanceState(savedState);
}
}
答案 0 :(得分:0)
您需要先在Facebook上提交您的应用程序,您可以从生成APP ID的控制台中找到它。因为facebook只允许一般 现在可以向应用程序发送个人资料信息,以获取分配给您的访 你需要创建:
然后在3-7天内,他们会授权您的应用访问您在提交时请求的其他权限。