Innim / flutter_login_vk

Flutter Plugin to login via VK.com
BSD 3-Clause "New" or "Revised" License
18 stars 20 forks source link

Getting the access code, but not getting any user info #40

Open ag0196 opened 1 year ago

ag0196 commented 1 year ago
import 'dart:developer';

import 'package:flutter_login_vk/flutter_login_vk.dart';

class VKAuthHelper {
  static String clientId = 'CLIENT_ID';
  static late VKLogin vk;
  init() async {
    vk = VKLogin();
    await vk.initSdk();
  }

  login() async {
    final res = await vk.logIn(
      scope: [
        VKScope.email,
        VKScope.friends,
      ],
    );

// Check result
    if (res.isValue) {
      // There is no error, but we don't know yet
      // if user loggen in or not.
      // You should check isCanceled
      final VKLoginResult? data = res.asValue?.value;
      if (data != null) {
        if (data.isCanceled) {
          return null;
        } else {
          debugger();
          // Send access token to server for validation and auth
          final VKAccessToken? accessToken = data.accessToken;
          print('Access token: ${accessToken?.token}');

          // Get profile data
          final profile = await vk.getUserProfile();
          VKUserProfile? userProfile = profile.asValue?.value;
          if (userProfile != null) {
            print(
                'Hello, ${userProfile.firstName}! You ID: ${userProfile.userId}');
          }
          // Get email (since we request email permissions)
          final email = await vk.getUserEmail();
          print('And your email is $email');
          return userProfile;
        }
      }
    } else {
      // Log in failed
      final errorRes = res.asError;
      print('Error while log in: ${errorRes!.error}');
      return null;
    }
  }
}

I have my code written as such, and I am getting the value of VKUserProfile? userProfile = profile.asValue?.value; and final email = await vk.getUserEmail(); as null. I am using Android, and everything seems to be set up as required in the documentation, and I was receiving at least the userProfile data before. I have recently created a release version of the app, so that may be a cause of this, or maybe the package update, I am not sure. Even though I've created an app release, I've added the SHA-1 key from the Play Console.

There're also some messages coming from WebView:


I/chromium(16669): [INFO:CONSOLE(168)] "Uncaught ReferenceError: onloadDeferStatic is not defined", source: https://oauth.vk.com/authorize?client_id=51508339&scope=EMAIL%2COFFLINE%2CFRIENDS&redirect_uri=https%3A%2F%2Foauth.vk.com%2Fblank.html&response_type=token&display=mobile&v=5.131&revoke=1 (168)

I/chromium(16669): [INFO:CONSOLE(210)] "Uncaught ReferenceError: onloadDeferStatic is not defined", source: https://oauth.vk.com/authorize?client_id=51508339&scope=EMAIL%2COFFLINE%2CFRIENDS&redirect_uri=https%3A%2F%2Foauth.vk.com%2Fblank.html&response_type=token&display=mobile&v=5.131&revoke=1 (210)

I/chromium(16669): [INFO:CONSOLE(1)] "Uncaught TypeError: window.onloadDeferStatic is not a function", source: https://st6-23.vk.com/dist/mobile/b-f1243200ebf4f876ae95512a66a57c53.dec24575a6be2cb7def4.js (1)

I/chromium(16669): [INFO:CONSOLE(1)] "Uncaught (in promise) ChunkLoadError: Loading chunk 1833 failed.

I/chromium(16669): (error: https://oauth.vk.com/dist/mobile/userInfoStats.641cd534a5c722d4329e.js)", source: https://st6-23.vk.com/dist/mobile/runtime.563113b2a0fe47cc32c1.js (1)

W/RenderInspector(16669): DequeueBuffer time out on com.monarchium.app/com.vk.api.sdk.ui.VKWebViewAuthActivity, count=1, avg=22 ms, max=22 ms.

W/cr_AwContents(16669): WebView.destroy() called while WebView is still attached to window.

W/ContentCatcher(16669): Failed to notify a WebView

I/flutter (16669): Access token: vk1.a.HNaqgwFQco6TlgON2fhJrJz9c_NCZZ7sa0A-f81_lsRF50su_ccXAvAQ7x4jlwIStRPHBkr3uFhSLqMq8gRgdls5_4gf2Khvc9FLMmr-jBGe6rRspcn3agODoQhYgmVd2epPwhfSz_3ifha4lFHKUjW4oVEVLCdL90tEQUXfwo968MIZVxsUPRP8EtD_or6aMWJkKdE-4NHMKmIEcQnaeA

I/flutter (16669): And your email is null