gpt4 book ai didi

java - 为什么我无法从 Facebook 获取生日信息

转载 作者:太空狗 更新时间:2023-10-29 14:06:19 24 4
gpt4 key购买 nike

这是我的代码。我收到电子邮件 fb id 性别名称但不是生日。我的代码有什么问题。我从 3 天开始搜索并尝试了很多次。

  showHashKey(getActivity());
View rootview = inflater.inflate(R.layout.fragment_main, container, false);

FacebookSdk.sdkInitialize(getActivity().getApplicationContext());
callbackManager = CallbackManager.Factory.create();

tv_facebook = (TextView) rootview.findViewById(R.id.tv_facebook);
Typeface arialblack_typeface = Typeface.createFromAsset(getActivity().getAssets(),
"arial_black.ttf");
tv_facebook.setTypeface(arialblack_typeface);
tv_facebook.setTextSize(40);
linearLayout = (LinearLayout) rootview.findViewById(R.id.inear_Layout);
linearLayout.setOnClickListener(this);
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
// login successful
Toast.makeText(getActivity(), " Main Activity in LoginResult on success", Toast.LENGTH_LONG).show();

// final AccessToken accessToken = loginResult.getAccessToken();

GraphRequest request = GraphRequest.newMeRequest
(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
// Application code
Log.v("MAinFrgment", response.toString());
System.out.println("Check: " + response.toString());
try {
String id = object.getString("id");
String name = object.getString("name");
String email = object.getString("email");
String gender = object.getString("gender");
String birthday = object.getString("birthday");
System.out.println(id + ", " + name + ", " + email + ", " + gender + ", " + birthday);
} catch (JSONException e) {
e.printStackTrace();
}

}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,gender,birthday");
request.setParameters(parameters);
request.executeAsync();
}

@Override
public void onCancel() {
// login cancelled
Log.e("OnCancel ","Oncancel");
}

@Override
public void onError(FacebookException exception) {
// login error
Log.e("OnCancel ","Error" +exception);
}
});
return rootview;

}


@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.inear_Layout:
LoginManager.getInstance().logInWithReadPermissions(getActivity(), Arrays.asList("public_profile,user_friends,user_birthday,user_about_me,email,basic_info"));

/* FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
Personal_Detail personal_detail = new Personal_Detail();

ft.replace(R.id.mainContainer,personal_detail);
ft.addToBackStack(null);
ft.commit();*/

break;
}

}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}

public static void showHashKey(Context context) {
try {
PackageInfo info = context.getPackageManager().getPackageInfo(
"google_play.flightdataui", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.i("KeyHash:",
Base64.encodeToString(md.digest(), Base64.DEFAULT));
// String abc = Base64.encodeToString(md.digest(),
// Base64.DEFAULT);
// System.out.println(abc);
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
}

}

这是响应。

{Response:  responseCode: 200, graphObject: {"id":"1488687718111904","gender":"male","email":"nafees4343@gmail.com","name":"Haider Rana"}, error: null}

问)如何获取用户生日 1?

最佳答案

LoginManager.getInstance().logInWithReadPermissions(WelcomeActivity1.this, (Arrays.asList("public_profile", "user_friends","user_birthday","user_about_me","email")));

在 oncreate 方法中尝试使用此代码:

LoginManager.getInstance().registerCallback(callbackManager,new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.d("tag","FF fb onSuccess");
GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(),new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object,GraphResponse response) {
try {
String[] splited ;
JSONObject obj = object.getJSONObject("picture").getJSONObject("data");

if (object.has("birthday"))
{
Birthday = object.getString("birthday");
}
else
{
Birthday = "";
}



} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,link,birthday,picture,email,gender");
request.setParameters(parameters);
request.executeAsync();


}

@Override
public void onCancel() {
Log.d("tag","fb onCancel");
// App code
}



@Override
public void onError(FacebookException exception) {
Log.d("tag","fb onError");
// App code
}
});

注意:另外,尝试使用不同的 FB 帐户,因为在某些 FB 帐户中,用户可能不会与他人分享他们的生日

关于java - 为什么我无法从 Facebook 获取生日信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32175021/

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