Beispiel #1
0
    def init_creds(credsb64):
        GDriveSync.LOCAL_TZ_OFFSET = GDriveSync.local_time_offset()
        if GDriveSync.CREDSB64 == credsb64:
            return
        creds_json = base64.b64decode(credsb64)
        creds = OAuth2Credentials.from_json(creds_json)
        GDriveSync.CREDS = creds
        GDriveSync.CREDSB64 = credsb64

        gauth = GoogleAuth()
        gauth.settings = {
            'client_config_backend': 'settings',
            'client_config_file': 'client_secrets.json',
            'save_credentials': False,
            'oauth_scope': ['https://www.googleapis.com/auth/drive'],
            'client_config': {
                'client_id': creds.client_id,
                'client_secret': creds.client_secret,
                'auth_uri': GOOGLE_AUTH_URI,
                'token_uri': GOOGLE_TOKEN_URI,
                'revoke_uri': GOOGLE_REVOKE_URI,
                'redirect_uri': 'http://juliabox.org/jboxauth/google/'
            }
        }
        gauth.LoadClientConfigSettings()
        gauth.credentials = creds
        GDriveSync.GAUTH = gauth

        GDriveSync.DRIVE = GoogleDrive(gauth)
Beispiel #2
0
    def setup(self):
        #create authorization helper and load default settings
        gauth = GoogleAuth(
            xbmc.validatePath(
                xbmc.translatePath(utils.addon_dir() +
                                   '/resources/lib/pydrive/settings.yaml')))
        gauth.LoadClientConfigSettings()

        #check if this user is already authorized
        if (not xbmcvfs.exists(
                xbmc.translatePath(utils.data_dir() + "google_drive.dat"))):
            settings = {
                "client_id": self.CLIENT_ID,
                'client_secret': self.CLIENT_SECRET
            }

            drive_url = gauth.GetAuthUrl(settings)

            utils.log("Google Drive Authorize URL: " + drive_url)

            code = xbmcgui.Dialog().input(
                'Google Drive Validation Code',
                'Input the Validation code after authorizing this app')

            gauth.Auth(code)
            gauth.SaveCredentialsFile(
                xbmc.validatePath(
                    xbmc.translatePath(utils.data_dir() + 'google_drive.dat')))
        else:
            gauth.LoadCredentialsFile(
                xbmc.validatePath(
                    xbmc.translatePath(utils.data_dir() + 'google_drive.dat')))

        #create the drive object
        self.drive = GoogleDrive(gauth)

        #make sure we have the folder we need
        xbmc_folder = self._getGoogleFile(self.root_path)
        print xbmc_folder
        if (xbmc_folder == None):
            self.mkdir(self.root_path)