Hi , 

Thank you for your reply.

I am facing some critical issue which will fail my platform.  

 This code was working perfect in v201603
    
    I can get access token, client_id, client secret and refresh token.
    But in this getClientInfo() is it giving me AdWordsUser class not 
found. i know that google removed but wht to replace it with ?
    
    I need to get these at final end : aw_oauth_refresh_token, 
aw_oauth_register_email, aw_client_id
        
    What changes i need to make in this from where i can see replaced 
method.
    
    My code sample which was working before below:
    
    
    //Import init.php from old adwords api v201603
    App::import('Vendor', 'AdwordsAPI', array('file' => 'adwords_api' . DS 
. 'init.php'));

    //First this method will run
    function admin_oauthCallBack($website_id = '') {
        $this->autoRender = false;

        $this->loadModel('Website');
        // Code begins
        $authorizationCode = '';
        $error = '';

        $oauthInfo = array();
        
        if (!empty($_REQUEST['code'])) {
            $authorizationCode = trim($_REQUEST['code']);
        }

        if (!empty($_REQUEST['error'])) {
            $error = trim($_REQUEST['error']);
        }

        if (!empty($_REQUEST['state'])) {
            $website_id = $_REQUEST['state'];
        }

        if (!empty($authorizationCode)) {

            $data = $this->getAccessToken($authorizationCode);
            

            if (!empty($data) && empty($data['error'])) {

                $accessToken = $data['access_token'];
                $refreshToken = $data['refresh_token'];
                
                // Customer Service (Single Adwords Account)
                
                $clientInfo = $this->getClientInfo($accessToken, 
$refreshToken);

                // Managed Customer Service (Manage Multiple Adwords 
Account)
                if (is_string($clientInfo)) {
                    $this->redirect(array('controller' => 'websites', 
'action' => 'listClients', $clientInfo, base64_encode($accessToken), 
base64_encode($refreshToken), base64_encode($website_id)));
                }

                if (!empty($clientInfo) && is_array($clientInfo)) {
                    $oauth_register_email = 
$this->getOauthRegisterEmail($accessToken);
                    $update_data = array(
                        'aw_oauth_refresh_token' => "'" . 
$clientInfo['oauth_refresh_token'] . "'",
                        'aw_oauth_register_email' => "'" . 
$oauth_register_email . "'",
                        'aw_client_id' => $clientInfo['client_id']
                    );

                    $condition = array('id' => $website_id);

                    $this->Website->updateAll($update_data, $condition);
                    $this->redirect(array('controller' => 'websites', 
'action' => 'index', 'admin' => true)); // clients
                } else {
                    $this->redirect(array('controller' => 'websites', 
'action' => 'index', 'admin' => true));
                }
            } else {
                $this->redirect(array('controller' => 'websites', 'action' 
=> 'index', 'admin' => true));
            }
        } else if (!empty($error)) {
            $this->Session->setFlash('Access Denied by User.', 'default', 
array('class' => 'error'));
            $this->redirect(array('controller' => 'websites', 'action' => 
'index', 'admin' => true));
        } else {
            
header("Location:https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=";
 
. Configure::read('AW_CLIENT_ID') . "&redirect_uri=" . 
Configure::read('REDIRECT_URI') . 
"&access_type=offline&approval_prompt=force&state=" . $website_id . 
"&scope=https://adwords.google.com/api/adwords/email";);
            die;
        }
    }
    
    
    function getClientInfo($access_token, $refresh_token) {

        $clients = array();
        try {

            $oauth2_info = array('client_id' => 
Configure::read('AW_CLIENT_ID'),
                'client_secret' => Configure::read('AW_CLIENT_SECRET'),
                'refresh_token' => $refresh_token
            );
            
            $user = new AdWordsUser();
            $user->SetOAuth2Info($oauth2_info);
            $user->LogAll();
            $customerService = $user->GetService('CustomerService', 
ADWORDS_VERSION);

            // Make the get request.
            $result = $customerService->get();

            if (!empty($result)) {

                $i = 0;

                $isMCC = $result->canManageClients;

                if (!$isMCC) {
                    $clients['client_id'] = $result->customerId;
                    $clients['oauth_refresh_token'] = $refresh_token;
                } else {
                    return $result->customerId;
                }
            }
        } catch (Exception $e) {
            pr($e->getMessage());
            die;
        }

        return $clients;
    }
    
    
    function getAccessToken($code) {

        $Rec_Data = array();

        if (!empty($code)) {

            $postFields = 'client_id=' . Configure::read('AW_CLIENT_ID') . 
'&client_secret=' . Configure::read('AW_CLIENT_SECRET') . '&code=' . $code 
. '&grant_type=authorization_code&redirect_uri=' . 
Configure::read('REDIRECT_URI');

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, 
'https://accounts.google.com/o/oauth2/token');
            curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);

            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

            $Rec_Data = curl_exec($ch);


            if (curl_exec($ch) === false) {
                return $Rec_Data;
                //echo 'Curl error: ' . curl_error($ch);
            }

            $Rec_Data = json_decode($Rec_Data, true);
        }

        return $Rec_Data;
    }
    
    
    function getOauthRegisterEmail($access_token) {
        $email = '';

        if (!empty($access_token)) {
            $url = 
"https://www.googleapis.com/oauth2/v2/userinfo?access_token="; . 
$access_token;

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);

            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

            $Rec_Data = curl_exec($ch);

            if (curl_exec($ch) === false) {
                return $email;
            }

            $Rec_Data = json_decode($Rec_Data, true);

            if (!empty($Rec_Data['email'])) {
                $email = trim($Rec_Data['email']);
            }
        }

        return $email;
    }
    
    
    ............................
    File init.php
    ............................
    
    // Set error reporting levels to highest
    error_reporting(E_STRICT | E_ALL);

    $depth = '/';
    define('SRC_PATH', dirname(__FILE__) . $depth . 'src/');
    define('LIB_PATH', 'Google/Api/Ads/AdWords/Lib');
    define('UTIL_PATH', 'Google/Api/Ads/Common/Util');
    define('ADWORDS_UTIL_PATH', 'Google/Api/Ads/AdWords/Util');

    define('ADWORDS_VERSION', 'v201603');

    // Configure include path
    ini_set('include_path', implode(array(
        ini_get('include_path'), PATH_SEPARATOR, SRC_PATH
    )));

    // Include the AdWordsUser
    require_once LIB_PATH . '/AdWordsUser.php';
    
    

Thanks,
Naresh Kumar
    
    
    


On Wednesday, January 11, 2017 at 11:37:30 AM UTC+5:30, Peter Oliquino 
wrote:
>
> Hi Naresh,
>
> The structures and path should not be an issue once you downloaded the 
> updated 
> client library <https://github.com/googleads/googleads-php-lib>. Your IDE 
> should be able to point to the correct packages/paths of the new versions 
> of the AdWords API client library files. You may also refer to the PHP 
> client library upgrade guide 
> <https://github.com/googleads/googleads-php-lib/blob/master/UPGRADING.md> for 
> more information.
>
> Thanks and regards,
> Peter
> AdWords API Team
>

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/3d93a453-2506-4d02-8214-af1f765ee6a1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to