Trying to Pull the DATA from the Double Click API (DFA)

455 views
Skip to first unread message

Rishav

unread,
Nov 28, 2013, 1:37:56 AM11/28/13
to google-doubleclick-...@googlegroups.com
Hi ALL

I am trying to pull the DATA from the Google DFA reporting Table.
After the Authentication Process using the Client Variable

Code::::::
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

client.oauth2credentials = credentials
advertiser_service = client.GetAdvertiserService(version='v1.19')
advertiser_search_criteria = {
      'Report_ID'
  }
    # Get advertiser record set.
    results = advertiser_service.GetAdvertisers(advertiser_search_criteria)[0]
    # Display advertiser names, IDs and spotlight configuration IDs.
    if results['records']:
        for advertiser in results['records']:
            print ('Advertiser with name \'%s\', ID \'%s\', and spotlight '
             'configuration id \'%s\' was found.' %
             (advertiser['name'], advertiser['id'], advertiser['spotId']))
    else:
        print 'No advertisers found for your criteria.'

Please Help me in this 

Joseph DiLallo (DFA API Team)

unread,
Dec 2, 2013, 9:40:09 AM12/2/13
to google-doubleclick-...@googlegroups.com
Hey Rishav,

It looks like you're searching for reports using the Trafficking API, not the DFA Reporting API. I think you want to look at these docs and these examples.

Cheers,
- Joseph DiLallo, the DFA API Team

Rishav

unread,
Dec 3, 2013, 1:57:52 AM12/3/13
to google-doubleclick-...@googlegroups.com

Hi Joseph
I have used the same doc But after the authentication 
all the Examples given are based on the command line arguments and I am not sure what arguments we need to pass in the 
Args value of the example and one more issue I am facing 

the Scope of the authentication says we must have both the Scope :


And How can I use both the Scope at the same time because I need to download the data from the DFA Reports.

Please help.

Rishav

unread,
Dec 3, 2013, 6:53:59 AM12/3/13
to google-doubleclick-...@googlegroups.com
Hi Joseph,
 
I have solved the Issues I have both the Scope in my mail using authentication of the app using the List as 

But Can you help me in pulling out the Data from the DFA reporting.
Examples given are based on the command line arguments and I am not sure what arguments we need to pass in the 
Args value of the exam

With Regards
Rishav 

Joseph DiLallo (DFA API Team)

unread,
Dec 3, 2013, 9:17:40 AM12/3/13
to google-doubleclick-...@googlegroups.com
Hey Rishav,

The examples contain a small description of the command line arguments when they set them up in the argparser. They should be visible using the --help flag from the command line, though you can also read them in the source code directly. Is there a particular example I can help you figure out? 

Cheers,
- Joseph DiLallo, the DFA API Team

Message has been deleted

Rishav

unread,
Dec 4, 2013, 1:10:54 AM12/4/13
to google-doubleclick-...@googlegroups.com


I have Done the authentication and after that
I am trying to download the file from the DFA 

 
//////////////////////Code//////////////////////////////
import httplib2
import os
import sys
import time
import urllib
import argparse
import pprint
import httplib



sys.path.insert(0, os.path.join('MY_dfa_api_auth.pkl_Location', 'MY_dfa_api_config.pkL_LOCATION', '..', '..'))
from adspygoogle import DfaClient
from oauth2client.client import FlowExchangeError
from oauth2client.client import OAuth2WebServerFlow
from apiclient import sample_tools
from oauth2client import client
from apiclient.discovery import build



DFA_USER_PROFILE_NAME ='DFA_USER_NAME'
# Visit https://code.google.com/apis/console to generate your client_id,
# client_secret and to register your redirect_uri.
# See the oauth2client wiki for more information on performing the OAuth2 flow:
# http://code.google.com/p/google-api-python-client/wiki/OAuth2
OAUTH2_CLIENT_ID = 'MyClientID'
OAUTH2_CLIENT_SECRET = 'MySecretkey '
dimension={}
report_id=REPORTID
profile_id=PROFILEID
file_id=FILEID

def main():
    # We're using the oauth2client library:
    
    scopeList = ["https://www.googleapis.com/auth/devstorage.read_only","https://www.googleapis.com/auth/dfareporting"]
    
    # http://code.google.com/p/google-api-python-client/downloads/list
    flow = OAuth2WebServerFlow(
                               client_id=OAUTH2_CLIENT_ID,
                               client_secret=OAUTH2_CLIENT_SECRET,
                               scope=scopeList,
                               redirect_uri='urn:ietf:wg:oauth:2.0:oob',
                               user_agent='SampleAPI')
    # Get the authorization URL to direct the user to.
    authorize_url = flow.step1_get_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()

    global credential 
 
    credential=None
    try:
        credential = flow.step2_exchange(code)
    except FlowExchangeError as e:
        sys.exit('Authentication has failed: %s' % e)

    # Create the DfpClient and set the OAuth2 credentials.
    client = DfaClient(headers={
                            'Username': DFA_USER_PROFILE_NAME,
                            'oauth2credentials': credential
                            })
    # OAuth2 credentials objects can be reused
    credentials = client.oauth2credentials
    client.oauth2credentials = credentials
    http = httplib2.Http()
    print 'OAuth2 authorization successful!'
    
    
   
    

    try :
        service = build('dfareporting', 'v1.3', http=http)
        report_file = service.reports().files().get(profileId=profile_id, reportId=report_id, fileId=file_id).execute()
        download_url = report_file['urls']['apiUrl']

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


/////////////////////////////////////////////////////////



/////////////////////On the CONSOLE////////////////////////////
//////////////////////////////////////////////////////////////

Log in to your Google Account and open the following URL: 

https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdevstorage.read_only+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdfareporting&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&client_id="Client ID"&access_type=offline

After approving the token enter the verification code (if specified).
Code:I have enter the Oauth Code !!! 


OAuth2 authorization successful!


HttpError 401 when requesting https://www.googleapis.com/dfareporting/v1.3/Profile_ID/reports/Report_ID/files/File_ID?alt=json returned "Login Required">
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////



Please help me where I am going wrong with the code and the authentication is failing ??

Joseph DiLallo (DFA API Team)

unread,
Dec 4, 2013, 2:00:02 PM12/4/13
to google-doubleclick-...@googlegroups.com
Hey Rishav,

We seem to be talking about this both here and on the issue tracker: https://code.google.com/p/google-api-ads-python/issues/detail?id=84  We should consolidate this discussion into just one of the channels.

Your problem seems to be that you're not authorizing the httplib2.http() object before you pass it into the DFA Reporting service object. You can do that like this:

  http = credentials.authorize(httplib2.Http())

Cheers,
- Joseph DiLallo, the DFA API Team
Reply all
Reply to author
Forward
0 new messages