Facebook SDKを介して、ユーザーの友人のデータ、具体的には誕生日にアクセスする方法のコードの例を挙げてください。すべては、Facebookのログインが完了したAndroid Studioを使用して行われます。友だちの誕生日にアクセスするFacebook sdk
私はアンドロイド開発には初めてです。この特定のプロジェクトは、アンドロイドとFacebookの統合に基づいています。ログインしてから、ユーザーの友人の誕生日にアクセスする必要があります。
public class MainActivityFragment extends Fragment {
private CallbackManager callbackManager;
private TextView textView;
private AccessTokenTracker accessTokenTracker;
private ProfileTracker profileTracker;
private FacebookCallback<LoginResult> callback = new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback(){
@Override
public void onCompleted(JSONObject object, GraphResponse response){
Log.v("LoginActivity",response.toString());
String email = object.getString("email");
String birthday = object.getString("birthday");
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,gender,birthday");
request.setParameters(parameters);
request.executeAsync();
Profile profile = Profile.getCurrentProfile();
displayMessage(profile);
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException e) {
}
};
public MainActivityFragment() {
}
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getActivity().getApplicationContext());
callbackManager = CallbackManager.Factory.create();
accessTokenTracker= new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(AccessToken oldToken, AccessToken newToken) {
// Set the access token using
// currentAccessToken when it's loaded or set.
}
};
profileTracker = new ProfileTracker() {
@Override
protected void onCurrentProfileChanged(Profile oldProfile, Profile newProfile) {
displayMessage(newProfile);
}
};
accessTokenTracker.startTracking();
profileTracker.startTracking();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_main, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
LoginButton loginButton = (LoginButton) view.findViewById(R.id.login_button);
textView = (TextView) view.findViewById(R.id.textView);
loginButton.setReadPermissions(Arrays.asList(
"public_profile", "email", "user_birthday", "user_friends"));
loginButton.setFragment(this);
loginButton.registerCallback(callbackManager, callback);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
private void displayMessage(Profile profile){
if(profile != null){
textView.setText(profile.getName());
}
}
@Override
public void onStop() {
super.onStop();
accessTokenTracker.stopTracking();
profileTracker.stopTracking();
}
@Override
public void onResume() {
super.onResume();
Profile profile = Profile.getCurrentProfile();
displayMessage(profile);
}
}
ようこそスタックオーバーフロー。あなたはあなたの質問を改善することができます。 [最小、完全、および検証可能な例](http://stackoverflow.com/help/mcve)をお読みください。あなたのコードが何も特別な問題であなたの正確な問題を示すとき、あなたはボランティアしてあなたを助ける人たちに敬意を表しています。 – zhon
スクロールを排除するためにコードを書式設定すると、他の人があなたを助けやすくなります。 – zhon