def authenticate_google_docs():
     credentials = SignedJwtAssertionCredentials(constants.EMAIL_ID, constants.SIGNED_KEY, constants.SCOPE)
     data = {
         'refresh_token': constants.REFRESH_TOKEN,
         'client_id': constants.CLIENT_ID,
         'client_secret': constants.CLIENT_SECRET,
         'grant_type': 'refresh_token',
     }
     r = requests.post('https://accounts.google.com/o/oauth2/token', data = data)
     credentials.access_token = ast.literal_eval(r.text)['access_token']
     service = discovery.build('drive', 'v2', http=credentials.authorize(Http()))
     media_body = MediaFileUpload('/tmp/dgtech.csv', mimetype='text/csv', resumable=True)
     file_metadata = {
       'title': 'dgtech.csv',
       'mimeType': 'application/vnd.google-apps.spreadsheet',
       'parents': [{'id': constants.FOLDER_ID}]
         }
     try:
         import pdb
         pdb.set_trace()
         param = {}
         children = service.children().list(folderId=constants.FOLDER_ID, **param).execute()
         file_list = [str(item['id']) for item in children['items']]
         print(file_list)
         service.children().delete(folderId=constants.FOLDER_ID, childId=file_list[0]).execute()
         file = service.files().insert(body=file_metadata, media_body=media_body, fields='id').execute()
         #logger.info("file id of the file upoaded = %s ", (file.get('id')))
     except Exception as e:
         print(str(e))
         #logger.exception("Exception occured while uploading the file")
Example #2
0
def authenticate_google_docs():
    # read .p12 file we generated in Google's console developer site
    #f = file(os.path.join('C:\\Users\\luiz.braz\\Desktop\\Projetos_Python\\IntegracaoGoogleSpreadSheet-536661d91d48.p12'), 'rb')
    f = file(
        os.path.join(
            '\\\\SRV-SQLMIRROR02\\M$\\Projetos\\Scripts_Python\\Exportacao_Arquivos_Google_Drive\\IntegracaoGoogleSpreadSheet-536661d91d48.p12'
        ), 'rb')
    #f = file(os.path.join('M:\\Projetos\\Scripts_Python\\IntegracaoGoogleSpreadSheet-536661d91d48.p12'), 'rb')
    SIGNED_KEY = f.read()
    f.close()

    # add some informations to authenticate
    scope = [
        'https://spreadsheets.google.com/feeds',
        'https://docs.google.com/feeds'
    ]
    credentials = SignedJwtAssertionCredentials('*****@*****.**',
                                                SIGNED_KEY, scope)

    # refresh_token we get from creds.data file
    # client_id and client_secret we get from OAuth 2.0
    data = {
        'refresh_token': '1/A6MISE7ZHFywZuQCkPhl4wDa2KAmDAYsQUol6sj3QZQ',
        'client_id':
        '202379785889-9ln68an8pr9o7ldlckaev64bjej76mnm.apps.googleusercontent.com',  # we won't modify this
        'client_secret': '7bf431wrB0zWxGyhDTRonKXl',  # we won't modify this
        'grant_type': 'refresh_token',
    }

    r = requests.post('https://accounts.google.com/o/oauth2/token', data=data)
    credentials.access_token = ast.literal_eval(r.text)['access_token']

    # try to authenticate
    gc = gspread.authorize(credentials)
    return gc
def authenticate_google_docs():
    f = file('barcode_attendance-d4cfa48c3d44.p12', 'rb') #referencing the file for Ouathorization
    SIGNED_KEY = f.read() #reading the file
    f.close()
    scope = ['https://spreadsheets.google.com/feeds', 'https://docs.google.com/feeds'] #connecting to sheets.google.com
    credentials = SignedJwtAssertionCredentials('*****@*****.**', SIGNED_KEY, scope) #sign in with email address

    data = {
        'refresh_token' : '4/LjtfNW4zjdf5qlIn0EkKHGskabs0gjSIeTGuzjfXxE4', #refresh token received from the oauth2token.py file, this is the string in the URL query in between the / /
        'client_id' : '411103951529-nf611s2285n12mmqrkigq3ckgkac1gmv.apps.googleusercontent.com', #client id from the .p12 file
        'client_secret' : 'uDKCenlmvo1desQfylHIUnYr', #client secret from .p12 file
        'grant_type' : 'refresh_token',
    }

    r = requests.post('https://accounts.google.com/o/oauth2/token', data = data)
    credentials.access_token = 'ya29..zAJqtxOTETQrsdBdJGXlnRiYnn1pMtxDt66N0r3JKkHKdiJChRpIDeIPQKxSI7ov1DZ_' #access token returned from the ouath2token.py program

    gc = gspread.authorize(credentials) #final step fro authorization
    return gc
def authenticate_google_docs():
    f = file(os.path.join('SSI Network Graphics-3357cb9f30de.p12'), 'rb')
    SIGNED_KEY = f.read()
    f.close()
    scope = ['https://spreadsheets.google.com/feeds', 'https://docs.google.com/feeds']
    credentials = SignedJwtAssertionCredentials('*****@*****.**', SIGNED_KEY, scope)

    data = {
        'refresh_token' : '1/NM56uCG7uFT6VVAAYX3B5TbcMk43wn1xE8Wr-7dsb7lIgOrJDtdun6zK6XiATCKT',
        'client_id' : '898367260-pmm78rtfct8af7e0utis686bv78eqmqs.apps.googleusercontent.com',
        'client_secret' : 'Cby-rjWDg_wWTSQw_8DDKb3v',
        'grant_type' : 'refresh_token',
    }

    r = requests.post('https://accounts.google.com/o/oauth2/token', data = data)
    credentials.access_token = ast.literal_eval(r.text)['access_token']

    gc = gspread.authorize(credentials)
    return gc
Example #5
0
def authenticate_gdocs():
    f = file(os.path.join('SpreeStockCount-95b566801cc4.p12'), 'rb')
    SIGNED_KEY = f.read()
    f.close()
    scope = ['https://spreadsheets.google.com/feeds', 'https://docs.google.com/feeds']
    credentials = SignedJwtAssertionCredentials('*****@*****.**', SIGNED_KEY, scope)

    data = {
        'refresh_token' : '1/gqqYJ7LKCR5xHlt0ADlhhbYQYJUi-w41HPA5_FOOtCgMEudVrK5jSpoR30zcRFq6',
        'client_id' : '293040254780-ovm9vrh8cl18fib06vb5er913s09ppg7.apps.googleusercontent.com',
        'client_secret' : 'AdGjPdVC6pBp7DJHhv45Pvkr',
        'grant_type' : 'refresh_token',
    }

    r = requests.post('https://accounts.google.com/o/oauth2/token', data = data)
    credentials.access_token = ast.literal_eval(r.text)['access_token']

    c = gspread.authorize(credentials)
    return c
def authenticate_google_docs():
    #f = file(os.path.join('C:/Users/d.kelly/Desktop/Python/bulkSummariser-f4e730f107d4.p12'), 'rb')
    f = file(os.path.join('//base4share/share/Doug/2015/checklistDataMining/bulkSummariser-f4e730f107d4.p12'), 'rb')
    SIGNED_KEY = f.read()
    f.close()
    scope = ['https://spreadsheets.google.com/feeds', 'https://docs.google.com/feeds', 'https://www.googleapis.com/auth/gmail.send']
    credentials = SignedJwtAssertionCredentials('*****@*****.**', SIGNED_KEY, scope)

    data = {
        'refresh_token' : '1/J9DflNyNnx2J9WnWtHsKnH9YDTTBTuoz3tJtnSXRtLc',
        'client_id' : '326340397307-lgicfbcjmu9863pjjkfrn0c5dviqsb42.apps.googleusercontent.com',
        'client_secret' : 'xeNtki_QWyoLaGEjYqtzF5si',
        'grant_type' : 'refresh_token',
    }

    r = requests.post('https://accounts.google.com/o/oauth2/token', data = data)
    credentials.access_token = ast.literal_eval(r.text)['access_token']

    gc = gspread.authorize(credentials)
    return gc