0

您好,这是代码,它确实检索用户信息,但是当我将其转换为 apk 时,它不会检索任何用户信息。请帮助:

GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(),
                    new GraphRequest.GraphJSONObjectCallback()
                    {
                        @Override
                        public void onCompleted(JSONObject object, GraphResponse response)
                        {
                            Log.i("LetsMeetFragment" + response.toString());

// imageURL = new URL(" https://graph.facebook.com/ " + userID + "/picture?width=" + width +"&height=" + height); // InputStream inputStream = (InputStream) imageURL.getContent(); // bitmap = getCroppedBitmap(BitmapFactory.decodeStream(inputStream));

                            try
                            {
                                String userID = (String) object.get("id");
                                letsMeetFlow.getUserUpdateRequestObj().setFb_id(userID);
                                BService.setFacebookID(userID);BService.setFacebookConnected(true);
                                PreferenceConnector.writeString(getContext(),ApplicationConstants.FacebookID, userID);


                                String userName = (String) object.get("name");
                                String DOB = (String) object.get("birthday");
                                String Gender = (String) object.get("gender");


                                if (Gender.equalsIgnoreCase("male"))
                                {
                                    manSeletion();
                                }
                                setBODField(DOB);

                                String[] userNamearray = userName.split(" ");
                                if (userNamearray.length > 1)
                                {
                                    String tmpName = "";
                                    for (int i = 0; i < userNamearray.length - 1; i++)
                                    {
                                        tmpName += userNamearray[i] + " ";
                                    }
                                    NameField.setText(tmpName.trim());
                                    LastNameField.setText(userNamearray[userNamearray
                                            .length - 1].trim());

                                }
4

1 回答 1

0

据我所知,您的代码在调试模式下有效,但是当您尝试编译签名的 apk 时停止工作。

这可能是签名哈希,您在 facebook 上拥有调试密钥的签名哈希,但是当您使用密钥编译时,哈希会发生变化

你可以做几件事来检索你的密钥的哈希一个是这个

public void printKeyHash() {
    try {
        PackageInfo info = getPackageManager().getPackageInfo("com.your.package.name.don't.forget.to.chang.this", PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.e("SHA: ", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
}

在启动时调整此代码并检查您的日志中的哈希值,它将打印一个读取文本,例如 SHA: xxxxYourHashxxxxx

复制粘贴此哈希并更新您在 Facebook 上的哈希。

于 2016-12-11T14:29:20.220 回答