storage=Storage(location of my credentials \SampleAD.dat') credential =storage.get() if credential is None: flow = OAuth2WebServerFlow( client_id=oauth2_client_id, client_secret=oauth2_client_secret, # Scope is the server address with '/api/adwords' appended. scope='https://adwords.google.com/api/adwords', user_agent='SampleAPI', redirect_uri='urn:ietf:wg:oauth:2.0:oob') authorize_url = flow.step1_get_authorize_url() print authorize_url webbrowser.open(authorize_url,) print ('Log in to your Google Account and open the following URL: \n%s\n' %authorize_url) print 'After approving the token enter the verification code (if specified).' code = raw_input('Code: ').strip() try: credential = flow.step2_exchange(code) storage=Storage('D:\Rishav_Work\Eclipse_WorkSpace\SampleAd.dat') client = AdWordsClient(headers={'developerToken': '%s++USD' % email, 'clientCustomerId': client_customer_id, 'userAgent': 'SampleAPI', 'oauth2credentials': credential }) credentials = client.oauth2credentials print 'OAuth2 authorization successful!'
# OAuth2 credential objects can be refreshed via credentials.refresh() - the # access token expires after 1 hour. credentials.refresh(httplib2.Http()) # Note: you could simply set the credentials as below and skip the previous # steps once access has been granted. client.oauth2credentials = credentials campaign_service = client.GetCampaignService(version='v201309') print campaign_service # OAuth2 credentials objects can be reused credentials = client.oauth2credentials client.oauth2credentials = credentials http = httplib2.Http() print http print 'OAuth2 authorization successful!' storage.put(credentials) except FlowExchangeError as e: sys.exit('Authentication has failed: %s' % e) else: client = AdWordsClient(headers={'developerToken': '%s++USD' % email, 'clientCustomerId': client_customer_id, 'userAgent': 'SampleAPI', 'oauth2credentials': credential }) credentials = client.oauth2credentials print 'OAuth2 authorization successful!' # OAuth2 credential objects can be refreshed via credentials.refresh() - the # access token expires after 1 hour. credentials.refresh(httplib2.Http()) # Note: you could simply set the credentials as below and skip the previous # steps once access has been granted. client.oauth2credentials = credentials campaign_service = client.GetCampaignService(version='v201309') # Get all campaigns. # Construct selector and get all campaigns. selector = { 'fields': ['Id', 'Name', 'Status'] } campaigns = campaign_service.Get(selector)[1] # Display results. if 'entries' in campaigns: for campaign in campaigns['entries']: print ('Campaign with id \'%s\', name \'%s\' and status \'%s\' was found.' % (campaign['id'], campaign['name'], campaign['status'])) else: print 'No campaigns were found.' # Initialize appropriate service. report_downloader = client.GetReportDownloader(version='v201309') report = { 'reportName': 'Last 7 days CRITERIA_PERFORMANCE_REPORT', 'dateRangeType': 'LAST_7_DAYS', 'reportType': 'CRITERIA_PERFORMANCE_REPORT', 'downloadFormat': 'CSV', 'selector': { 'fields': ['CampaignId', 'AdGroupId', 'Id', 'CriteriaType', 'Criteria', 'Impressions', 'Clicks', 'Cost'] }, # Enable to get rows with zero impressions. 'includeZeroImpressions': 'false' } print report_downloader.DownloadReport(report) I am getting this error ============================================================================== raise MissingPackageError(msg) adspygoogle.common.Errors.MissingPackageError: PyXML v0.8.3 or newer is required. ============================================================================== -- -- =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ Also find us on our blog and Google+: https://googleadsdeveloper.blogspot.com/ https://plus.google.com/+GoogleAdsDevelopers/posts =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ You received this message because you are subscribed to the Google Groups "AdWords API Forum" group. To post to this group, send email to adwords-api@googlegroups.com To unsubscribe from this group, send email to adwords-api+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/adwords-api?hl=en --- You received this message because you are subscribed to the Google Groups "AdWords API Forum" group. To unsubscribe from this group and stop receiving emails from it, send an email to adwords-api+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.