Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying Oauth Using the clientsecrets JSON #316

Open
GoogleCodeExporter opened this issue May 13, 2015 · 0 comments
Open

Trying Oauth Using the clientsecrets JSON #316

GoogleCodeExporter opened this issue May 13, 2015 · 0 comments

Comments

@GoogleCodeExporter
Copy link

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 [email protected] on 12 Dec 2013 at 4:19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant