lulu-berlin / google-api-python-client

Automatically exported from code.google.com/p/google-api-python-client
Other
0 stars 0 forks source link

Trying Oauth Using the clientsecrets JSON #316

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What is am trying to get the reports from the DFA REPORTING !!
I am trying to use Oauth Using the clientsecrets JSON
But I am stuck at few Codes !! 

1st one Using the Self !! 
what is self in the Code ?

2nd how can we Import StorageByKeyName ?
I have googled a lot about it ? I am clue less !
I have used the oauth2.0 given at the Google Oauth and it code using 
clientsecrets 

My code
=====================================================================

from oauth2client.client import flow_from_clientsecrets
from oauth2client.file import Storage
from oauth2client.client import FlowExchangeError
from apiclient.discovery import build
import httplib2

scopeList = 
["https://www.googleapis.com/auth/devstorage.read_only","https://www.googleapis.
com/auth/dfareporting"]
profile_id=1111
report_id=22222
file_id=33333
def main():
    try:
        flow = flow_from_clientsecrets('MY_JSON_FILE_LOCATION',
                               scope=scopeList,
                               redirect_uri='urn:ietf:wg:oauth:2.0:oob')
        print 'flow:',flow
        authorize_url = flow.step1_get_authorize_url()
        self.redirect(authorize_url)
        credential = flow.step2_exchange(self.request.params)
        storage=StorageByKeyName(Credentials,user.user_id(),credential)
        credentials=storage.get()
        http=httplib2.Http()
        http=credentials.authorize(http)
        http = credentials.authorize(http)
        print http
        service = build('dfareporting', 'v1.3', http=http)
        print 'Service',service
        report_file = service.reports().files().get(profileId=profile_id, reportId=report_id, fileId=file_id).execute()
        print report_file
        download_url = report_file['urls']['apiUrl']
        print download_url

        response, content = http.request(download_url)
        if response['status'] == '200':
            print content
    except BaseException as e:
        print ('Error at ',e)
if __name__ == '__main__':
    main()

Original issue reported on code.google.com by rishav...@gmail.com on 12 Dec 2013 at 4:19