How to get Customer Id with username and password

729 views
Skip to first unread message

Sachin Kumar

unread,
Feb 3, 2017, 10:07:32 AM2/3/17
to AdWords API Forum, Harisankar Mohanty
Hello Team,

Object: To get customer Id with the help of adwords account's username and password.

I have user's adwords account username and password. Now I want to get customer Id related to this username and password and then add this customer Id to mcc account.


Kindly suggest a way or snippet of code to achieve this.


Regards
Sachin
 

Shwetha Vastrad (AdWords API Team)

unread,
Feb 3, 2017, 11:00:26 AM2/3/17
to AdWords API Forum, harish....@gmail.com
Hi Sachin,

To retrieve the CustomerId using the account's username and password, you need to follow these steps:
  1. Generate client ID and client secret by following the instructions provided here. Once you have the OAuth2 credentials, you need to generate the refresh token using any of the client libraries
  2. Use CustomerService.getCustomers() method without setting the clientCustomerId header along with the credentials generated. The response will contain the details of the authenticated account. 
Regards,
Shwetha, AdWords API Team.

Sachin Kumar

unread,
Feb 4, 2017, 10:47:22 AM2/4/17
to AdWords API Forum, harish....@gmail.com
Hello Shwetha,

Thank you for your reply.

I successfully authenticate the request and get users email/name etc. but not get "Customer Id". This is the user's data as response which I got:

Array
(
    [id] => **************
    [email] => *****@gmail.com
    [verified_email] => 1
    [name] => Sachin Kumar
    [given_name] => Sachin
    [family_name] => Kumar
    [link] => https://plus.google.com/**************
    [picture] => https://lh4.googleusercontent.com/-CxjPiLZwnPM/AAAAAAAAAAI/AAAAAAAAALI/QMgIXPAnqng/photo.jpg
    [gender] => male
    [locale] => en
)

Here is the code to get this response:

<?php
   
    session_start();
   
    global $objGoogleClient;
    global $objGoogleOauth;
   
    require 'login-with-google/config.php';
   
    $objGoogleClient = $gClient;
   
    if(! isset($_REQUEST['code'])){
        header('Location: ' . $objGoogleClient->createAuthUrl());
    }
    if (isset($_REQUEST['code'])) {
        $objGoogleClient->authenticate();
        $accessToken = $objGoogleClient->getAccessToken();
        $_SESSION['token'] = $accessToken;
        $_SESSION['googlePlusToken'] = $accessToken;
    }

    if (isset($_SESSION['token'])) {
        $objGoogleClient->setAccessToken($_SESSION['token']);
    }

    if ($objGoogleClient->getAccessToken()) {
       
        $gpUserData = $google_oauthV2->userinfo->get();
        echo '<pre>';
        print_r($gpUserData);
        die('huuu');
    }



Can you plz provide some piece of code or suggestion?


Regards,
Sachin

Shwetha Vastrad (AdWords API Team)

unread,
Feb 6, 2017, 10:33:03 AM2/6/17
to AdWords API Forum, harish....@gmail.com
Hi Sachin,

Once you have the access token associated with the email address in question, you need to perform a CustomerService.getCustomers() request with the clientCustomerId header unset. An example SOAP request and response looks like this:

Request:
<?xml version="1.0"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 
<soapenv:Header>
   
<ns1:RequestHeader xmlns:ns1="https://adwords.google.com/api/adwords/cm/v201609" soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0">
     
<ns1:developerToken>YOUR_DEVELOPER_TOKEN</ns1:developerToken>
     
<ns1:userAgent>YOUR_APPLICATION_NAME</ns1:userAgent>
     
<ns1:validateOnly>false</ns1:validateOnly>
     
<ns1:partialFailure>false</ns1:partialFailure>
   
</ns1:RequestHeader>
 
</soapenv:Header>
 
<soapenv:Body>
       
<getCustomers xmlns="https://adwords.google.com/api/adwords/mcm/v201609"/>
 
</soapenv:Body>
</soapenv:Envelope>


Response:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   
<soap:Header>
       
<ns2:ResponseHeader xmlns="https://adwords.google.com/api/adwords/cm/v201609" xmlns:ns2="https://adwords.google.com/api/adwords/mcm/v201609">
           
<requestId>000547de2be2e8600a819cca21042387</requestId>
           
<serviceName>CustomerService</serviceName>
           
<methodName>getCustomers</methodName>
           
<operations>1</operations>
           
<responseTime>470</responseTime>
       
</ns2:ResponseHeader>
   
</soap:Header>
   
<soap:Body>
       
<ns2:getCustomersResponse xmlns="https://adwords.google.com/api/adwords/cm/v201609" xmlns:ns2="https://adwords.google.com/api/adwords/mcm/v201609">
           
<ns2:rval>
               
<ns2:customerId>1234567890</ns2:customerId>
               
<ns2:currencyCode>USD</ns2:currencyCode>
               
<ns2:dateTimeZone>America/New_York</ns2:dateTimeZone>
               
<ns2:descriptiveName>Account_Name</ns2:descriptiveName>
               
<ns2:canManageClients>true</ns2:canManageClients>
           
</ns2:rval>
       
</ns2:getCustomersResponse>
   
</soap:Body>
</soap:Envelope>

Reply all
Reply to author
Forward
0 new messages