403 Error: disallowed_useragent

I am new to mobile app development, I am developing an ios app. In which I use the Google drive to get document files in my application from google account. I did this task and worked great. But now it does not work now, when I try to authenticate it, it shows 403 Error: disallowed_useragent in my application. I was looking for this in relation to Google, but something embarrassing, I read this stack overflow question from finding that the Google drive was updated, now I don’t know if I want to repeat my task or should I update the login task only to complete it, kindly have someone tell me about it

thanks for the help

+3
source share
4 answers

After the Google Drive API starts up quickly, add these 3 lines of code to AppDelegate.m doneFinishLaunchingWithOptions, as shown below .. then it works fine ...

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSString *userAgent = @"Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/603.1.23 (KHTML, like Gecko) Version/10.0 Mobile/14E5239e Safari/602"; // set default user agent NSDictionary *dictionary = [[NSDictionary alloc]initWithObjectsAndKeys:userAgent,@"UserAgent", nil]; [[NSUserDefaults standardUserDefaults] registerDefaults:(dictionary)]; return YES; } 
+13
source

There is a workaround for this issue after a recent change in the Google OAuth policy.

After integrating the Google Sign and enabling the Google Drive API, I was able to work with the Google Drive API to get all the drive data. We just need to install the authorizer for GTLServiceDrive, which is obtained after logging in to Google.

service.authorizer = user.authentication.fetcherAuthorizer()

Here are the snippets of Google GIDSignIn code, and then fetching calendar events.

  import GoogleAPIClient import GTMOAuth2 import UIKit import GoogleSignIn class ViewController: UIViewController, GIDSignInUIDelegate, GIDSignInDelegate { private let kApiKey = "AIzaXXXXXXXXXXXXXXXXXXXXXXX" // If modifying these scopes, delete your previously saved credentials by // resetting the iOS simulator or uninstall the app. private let scopes = [kGTLAuthScopeDriveMetadataReadonly] private let service = GTLServiceDrive() override func viewDidLoad() { super.viewDidLoad() service.apiKey = kApiKey GIDSignIn.sharedInstance().uiDelegate = self GIDSignIn.sharedInstance().scopes = scopes GIDSignIn.sharedInstance().signIn() GIDSignIn.sharedInstance().delegate = self } func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) { if user != nil { print("\(user)") service.authorizer = user.authentication.fetcherAuthorizer() loadDriveFiles() } } // Construct a query and get a list of upcoming events from the user calendar func loadDriveFiles() { //Googly Drive fetch Query } } 
+3
source

Google changes its Oauth policies, it is assumed that no native web views trigger Oauth streams, I also work with the iOS application and have the same problem, you probably should wait for their SDK and documentation to be updated or find an alternative authentication method for use of user information.

0
source

An alternative way is to use a third-party CloudRail SDK, which can use an external browser for authentication. This blog post covers exactly the issue you mentioned.

-1
source

Source: https://habr.com/ru/post/1259750/


All Articles