Linking account by PHP api

315 views
Skip to first unread message

sup...@grafxsoftware.com

unread,
May 23, 2014, 9:15:49 AM5/23/14
to adwor...@googlegroups.com
Hi!

I tried to link an account with this code in php AdWords api:

private function linkingUser( & $data )
    {
       
        // Get the service, which loads the required classes.
        $managedCustomerService =
            $this->user->GetService('ManagedCustomerService', ADWORDS_VERSION);


        $link = new ManagedCustomerLink();
        $link->clientCustomerId = $data["googleClientId"];//CLIENT_CID;
        $link->pendingDescriptiveName = "";
        $link->linkStatus = 'PENDING';
        $link->managerCustomerId = $data["googleClientId"];//MANAGER_CID;
       
        // Create operation.
        $operation2 = new LinkOperation();
       
        $operation2->operand = $link;
        $operation2->operator = 'ADD';

        $operations = array( $operation2);
       
       
       
        try
        {
            // Make the mutate request.
            $result = $managedCustomerService->mutate( $operations );
        }
        catch (Exception $e) {
            $this->errors[] = $this->parseAdWordsError( $e->getMessage() );
            return FALSE;
        }
       
       
        if( empty( $result->value[0] ) )
        {
            $error = "AdWordsUser not created (garfx)." ;
            $this->errors[] = $error;
            return FALSE;
        }
               
        return $result->value[0];
    }
   
The response was:

[RequiredError.REQUIRED @ operations[0].operand.customerCurrencyCode, RequiredError.REQUIRED @ operations[0].operand.clientName, RequiredError.REQUIRED @ operations[0].operand.dateTimeZone]

Please help me. What is wrong with my code?

Thx.

Michael Cloonan (AdWords API Team)

unread,
May 23, 2014, 10:28:41 AM5/23/14
to adwor...@googlegroups.com
Hello,

It looks like you're using the same CID for both clientCustomerId and managerCustomerId, which is not correct. The ManagedCustomerLink is useful for linking two pre-existing accounts together. If you only have one ID available, then you should most likely be creating a new ManagedCustomer instead.

You can see an example of how to do that in PHP here.

Alternatively, if you really do have an MCC account and a client account you would like to link, be sure to use the correct IDs in those two fields to set up the link properly. I think the error you're seeing is likely because you put an MCC id in the clientCustomerId field, and then the required fields weren't found on the existing account.

Regards,
Mike, AdWords API Team

sup...@grafxsoftware.com

unread,
May 26, 2014, 11:05:11 AM5/26/14
to adwor...@googlegroups.com
Hi!

Thanks for the answer!
I tried to link an account with php AdWords api (v201309):
Now the clientCustomerId is the id of the client, and the managerCustomerId = $this->user->GetClientCustomerId();
$this->user is the user of my MCC account. ( Like in the examples $user )

The code is:
// $data is prevalidated data from post.

private function linkingUser( & $data )
    {
        // Get the service, which loads the required classes.
        $managedCustomerService =
            $this->user->GetService('ManagedCustomerService', ADWORDS_VERSION);

        $link = new ManagedCustomerLink();
        $link->clientCustomerId = $data["clientId"]; //CLIENT_CID;
        $link->pendingDescriptiveName = "PENDING: " . $data["clientId"];
        $link->linkStatus = 'PENDING';
        $link->managerCustomerId = $this->user->GetClientCustomerId(); //MANAGER_CID;
       
        // Create operation.
        $operation = new LinkOperation();
       
        $operation->operand = $link;
        $operation->operator = 'ADD';

        $operations = array(  $operation );


        try
        {
            // Make the mutate request.
            $result = $managedCustomerService->mutate( $operations );
        }
        catch (Exception $e) {
            $message = $e->getMessage();
            $this->errors[] = $message;

            return FALSE;
        }
       
        if( empty( $result->value[0] ) )
        {
            $error = "Linking failed (garfx)." ;

            $this->errors[] = $error;
            return FALSE;
        }
               
        return $result->value[0];
    }
Probleme 1.)
The result from "catch" section is: {"error" : "unauthorized_client"}

Probleme 2.)
curl probleme in API:
Warning: curl_setopt(): CURLOPT_FOLLOWLOCATION cannot be activated when an open_basedir is set in /var/www/vhosts/grafxsoftware.com/httpdocs/gapi/src/Google/Api/Ads/Common/Util/CurlUtils.php on line 107

Thanks for helping.

Grafx.



-----------------------------------------------------------------------------------------------------------------

Michael Cloonan (AdWords API Team)

unread,
May 27, 2014, 3:10:43 PM5/27/14
to adwor...@googlegroups.com
Hello,

This sounds like it may be a bug with our PHP library, or with a configuration on your server that conflicts with our PHP library.

Could you open a bug for this issue at our library page on GitHub? They will be able to better assist you there with the client-library specific concern.

Regards,
Mike, AdWords API Team

sup...@grafxsoftware.com

unread,
Jun 2, 2014, 9:33:12 AM6/2/14
to adwor...@googlegroups.com
Hi

I'm trying to link an user with this code:

/**
     *
     * @param type $data
     */

    private function linkingUser( & $data )
    {
        // Get the service, which loads the required classes.
        $managedCustomerService =
            $this->user->GetService('ManagedCustomerService', ADWORDS_VERSION);
         
        $link = new ManagedCustomerLink();
        $link->clientCustomerId = $data["googleClientId"]; //CLIENT_CID;
        $link->pendingDescriptiveName = "PENDING " . $data["googleClientId"];

        $link->linkStatus = 'PENDING';
        $link->managerCustomerId = $this->user->GetClientCustomerId(); //MANAGER_CID;
       
        // Create operation.
        $operation2 = new LinkOperation();
       
        $operation2->operand = $link;
        $operation2->operator = 'ADD';

        $operations = array( $operation2);

        try
        {
            // Make the mutate request.
            $result = $managedCustomerService->mutate( $operations );
        }
        catch (Exception $e) {
            $message = $e->getMessage();
            $this->errors[] = $message;
            return FALSE;
        }
       
        if( empty( $result->value[0] ) )
        {
            $error = "AdWordsUser not created (garfx)." ;
            $this->errors[] = $error;
            return FALSE;
        }
               
        return $result->value[0];
    }

The result from "catch" section is: {"error" : "unauthorized_client"}
Is possible that my clientID doesn't have right to link another user account?
Which case can I get this error message?

Thnaks for response.

Grafx.

Michael Cloonan (AdWords API Team)

unread,
Jun 3, 2014, 10:07:50 AM6/3/14
to adwor...@googlegroups.com
Hello,

Can you please provide the full SOAP request/response you're getting when executing this by replying to me privately using the drop down arrow and "reply to author"? This will help me determine what the probable cause of this error is.

Regards,
Mike, AdWords API Team

asma batool

unread,
Jun 23, 2016, 4:40:05 AM6/23/16
to AdWords API Forum
Hi,

I am also having issue linking account 
but errors is [ManagedCustomerServiceError.NOT_AUTHORIZED @ operations[0]]

Michael Cloonan (AdWords API Team)

unread,
Jun 23, 2016, 9:36:29 AM6/23/16
to AdWords API Forum
Hello,

If you are having a separate issue, please create a new forum thread and please provide more information about exactly what you are trying (preferably with SOAP).

Unfortunately, we have determined that to accept a link request from a client account via the API, you have to authorize as the client account itself. Maybe try using a refresh token generated directly from the client account you wish to link to. At that point, however, you are already logged into the child account manually, so it may be easier to just accept the link manually. We are working with the API team to determine a way to improve the ability to programmatically link accounts without requiring manual user intervention to get authorization.

Regards,
Mike, AdWords API Team
Reply all
Reply to author
Forward
0 new messages