gpt4 book ai didi

android - Google Drive Android API ConnectionResult 错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:03:16 26 4
gpt4 key购买 nike

我正在制作一个应用程序并将 Google Drive Android API 集成到其中。我有一个主要 Activity ,然后是一个 fragment ,该 fragment 打开导致谷歌驱动器。但是,当我尝试登录时(不管是什么 gmail 帐户,我都尝试过现有帐户、创建新帐户等等),我收到 ConnectionResult 错误代码 17 SIGN_IN_FAILED。该应用程序已在开发者控制台中获得授权并启用了 Drive API。我不知道还能做什么。

相关代码如下:

public class FileSharingFragment extends Fragment implements
GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
mGoogleApiClient.connect();
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_file_sharing, container, false);
users = (TextView) rootView.findViewById(R.id.users);
getActivity().setTitle("Files");
return rootView;
}

@Override
public void onActivityResult(int requestCode, int resultCode,
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE_RESOLUTION && resultCode == Activity.RESULT_OK) {
mGoogleApiClient.connect();
}
}

@Override
public void onConnectionFailed(ConnectionResult result) {
Log.i(TAG, "GoogleApiClient connection failed: " + result.toString());
if (!result.hasResolution()) {
// show the localized error dialog.
GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), getActivity(), 0).show();
Log.i("file sharing fragment", "error code " + result.getErrorCode());
return;
}
try {
result.startResolutionForResult(getActivity(), REQUEST_CODE_RESOLUTION);
} catch (IntentSender.SendIntentException e) {
Log.e(TAG, "Exception while starting resolution activity", e);
}
}

并从我使用的主要 Activity 中调用它

Fragment fragment = FileSharingFragment.newInstance();
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

我一辈子都弄不明白为什么它不让我登录。

最佳答案

您现在可能知道您的 Developers Console需要三样东西:

1/APK 的 SHA1
2/你的包名
3/您在同意屏幕中的电子邮件/产品名称

假设一切正常,这是我经常使用的最后手段复查:
- 使用解压器(如 7zip)打开(解压)您的 xxxx.APK,找到 CERT.RSA。
- 运行 'keytool -printcert -file .........\CERT.RSA'
返回控制台并再次比较 SHA1。

祝你好运

关于android - Google Drive Android API ConnectionResult 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29689832/

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