无法实施Google注册Android

时间:2016-05-06 16:54:03

标签: android

尝试实施Google注册Android应用,代码如下:

// values.txt
SP=['var1','var2','var3','var4','var5','var6']

// or values.json
{ SP: ['var1','var2','var3','var4','var5','var6'] }

我已根据google指令重新检查了所有先决条件,但由于public class MainActivity extends AppCompatActivity implements View.OnClickListener, GoogleApiClient.OnConnectionFailedListener { //Signin button private SignInButton signInButton; //Signing Options private GoogleSignInOptions gso; //google api client private GoogleApiClient mGoogleApiClient; //Signin constant to check the activity result private int RC_SIGN_IN = 100; //TextViews private TextView textViewName; private TextView textViewEmail; private NetworkImageView profilePhoto; //Image Loader private ImageLoader imageLoader; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //Initializing Views textViewName = (TextView) findViewById(R.id.textViewName); textViewEmail = (TextView) findViewById(R.id.textViewEmail); profilePhoto = (NetworkImageView) findViewById(R.id.profileImage); //Initializing google signin option gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestEmail() .build(); //Initializing signinbutton signInButton = (SignInButton) findViewById(R.id.sign_in_button); signInButton.setSize(SignInButton.SIZE_WIDE); signInButton.setScopes(gso.getScopeArray()); //Initializing google api client mGoogleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) .build(); //Setting onclick listener to signing button signInButton.setOnClickListener(this); } //This function will option signing intent private void signIn() { //Creating an intent Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient); //Starting intent for result startActivityForResult(signInIntent, RC_SIGN_IN); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); //If signin if (requestCode == RC_SIGN_IN) { GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); //Calling a new function to handle signin handleSignInResult(result); } } //After the signing we are calling this function private void handleSignInResult(GoogleSignInResult result) { //If the login succeed if (result.isSuccess()) { //Getting google account GoogleSignInAccount acct = result.getSignInAccount(); //Displaying name and email textViewName.setText(acct.getDisplayName()); textViewEmail.setText(acct.getEmail()); } else { //If login fails Toast.makeText(this, "Login Failed", Toast.LENGTH_LONG).show(); } } @Override public void onClick(View v) { if (v == signInButton) { //Calling signin signIn(); } } @Override public void onConnectionFailed(ConnectionResult connectionResult) { } } 一次又一次result.isSuccess(),我的登录失败了。我见过很多人对此错误感到疑惑,但在任何地方都没有明确的解决方案。有什么东西显而易见吗?

2 个答案:

答案 0 :(得分:1)

您未连接GoogleApiClient。根据文档here

  

您应该在Activity中实例化一个客户端对象   onCreate(Bundle)方法,然后在connect()onStart()中调用disconnect()   onStop()中的connect(),与州无关。

因此,您需要disconnect()并随后GoogleApiClient #If you aren't using Response: from rest_framework.response import Response class PersonListViewSet(viewsets.ModelViewSet): def get(self, request): queryset = Person.objects.all() serializer_class = PersonListSerializer(queryset, many=True) #It may change the things return Response(serializer_class.data) class PersonViewSet(viewsets.ModelViewSet): def get(self, request, pk): #specify the method is cool queryset = Person.objects.all() serializer_class = PersonSerializer(queryset, many=True) #Here as well #return Response(serializer_class.data)

答案 1 :(得分:0)

您必须为此创建已签名的APK。确保使用不同的SHA密钥进行发布。然后生成APK并直接将其安装在手机上。它应该这样工作。