3

I am new to mobile application development, I am developing an ios app. In which I am using google drive to get document files into my app from google account.I did that task and worked fine.But now it is not working now when I try to authenticate it shows 403 Error: disallowed_useragent in my app . I googled regarding that but somethig confusing, I read this stack overflow question from that I found google drive has updated,now I donnot know whether I want redo my task or have to update task for signin only to complete it, kindly any one suggest me regarding that

Thanks in advence

Community
  • 1
  • 1
  • show your code or the HTTP reuqest or something? – Liam Nov 17 '16 at 12:05
  • http://stackoverflow.com/questions/40233330/cannot-download-file-from-google-drive-in-ios?noredirect=1#comment68213104_40233330 – sathya chinnasamy Nov 17 '16 at 12:10
  • @Liam please see above link that is my question while did this task everything is there what i did – sathya chinnasamy Nov 17 '16 at 12:11
  • So you saying this is a duplicate? – Liam Nov 17 '16 at 12:11
  • Because you [shouldn't ask the same question multiple times](http://stackoverflow.com/help/duplicates). If you want to draw attention to a question then add a bounty – Liam Nov 17 '16 at 12:12
  • @Liam I am not sure please guid me regarding that – sathya chinnasamy Nov 17 '16 at 12:13
  • Possible duplicate of [403 Error - Thats an error. Error: disallowed\_useragent](http://stackoverflow.com/questions/40591090/403-error-thats-an-error-error-disallowed-useragent) – DaImTo Nov 17 '16 at 12:17
  • 1
    http://stackoverflow.com/a/40605255/1841839 is the correct answer looks like the issue has been reported for drive. You will have to wait for them to update the sdk – DaImTo Nov 17 '16 at 12:21
  • i cannot get clear idea http://stackoverflow.com/questions/40591090/403-error-thats-an-error-error-disallowed-useragent from this ,If any one say the answer means will be better – sathya chinnasamy Nov 17 '16 at 12:23
  • I pinged google for you as well. Cant guarantee a speedy response. – DaImTo Nov 17 '16 at 12:26
  • @ DaImTo can you say me clearly i cannot get you, what is the exact problem ? – sathya chinnasamy Nov 17 '16 at 12:39
  • Google has updated its security restrictions for OAuth flow. They are not going to allow native web-views to initiate OAuth flows, but rather are encouraging people to use the OS browsers to do so. The sdk you are using uses native web-views I suspect. You will have to wait for the sdk to be updated. – DaImTo Nov 17 '16 at 12:41
  • @DaImToany guess you have time taken to update ? – sathya chinnasamy Nov 17 '16 at 12:45
  • I linked your question someone may respond. but this is google if it is a bug on their side your just going to have to wait. unless you can switch the code to use an OS browser yourself. I am not an iOS dev so don't have a clue about how to do that. – DaImTo Nov 17 '16 at 12:54

4 Answers4

14

After Following Google drive API Quick start, Add these 3 lines of code in AppDelegate.m didFinishLaunchingWithOptions 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;
}
Bhumika
  • 876
  • 7
  • 20
3

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

After integrating the Google Sign and enabling Google Drive API, I was able to work with Google Drive API to fetch all drive data. We just have to set the authorizer for GTLServiceDrive which is obtained after Google sign-in.

service.authorizer = user.authentication.fetcherAuthorizer()

Here is the code snippets of Google GIDSignIn, followed by 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
       }

   }
Jen Jose
  • 3,945
  • 2
  • 17
  • 36
0

Google is changing its Oauth policies, with this it is intended that no native web views initiate Oauth flows, I am working with an iOS app too and having the same problem, you should probably wait for them to update the SDKs and documentation or find an alternate way of authenticating to use the users information.

-1

An alternative way is to use the 3rd party CloudRail SDK which can use an external browser for the authentication. This blog post covers exactly the issue you've mentioned.

Tmm
  • 191
  • 4