Need help with Scope for "Self Client"

Need help with Scope for "Self Client"

Trying to use self client to query contact by email address.

I tried following
aaaserver.profile.ALL,ZohoCRM.modules.ALL,ZohoCRM.bulk.ALL,ZohoCRM.settings.ALL,ZohoCRM.settings.fields.ALL
OR
aaaserver.profile.all,ZohoCRM.modules.all,ZohoCRM.bulk.ALL,ZohoCRM.settings.all,ZohoCRM.settings.fields.all 

but I can not get it work, I keep getting error "invalid oauth scope to access this URL"

<?php
define('ROOT_HOME', '');


require_once ROOT_HOME . 'vendor/autoload.php';

use com\zoho\api\authenticator\OAuthBuilder;
use com\zoho\api\authenticator\store\FileStore;
use com\zoho\crm\api\dc\USDataCenter;
use com\zoho\crm\api\InitializeBuilder;
use com\zoho\crm\api\query\APIException;
use com\zoho\crm\api\query\BodyWrapper;
use com\zoho\crm\api\query\QueryOperations;
use com\zoho\crm\api\query\ResponseWrapper;
use com\zoho\crm\api\SDKConfigBuilder;
use com\zoho\crm\api\UserSignature;
use com\zoho\crm\api\util\Choice;

//use com\zoho\crm\api\query\Query;


$environment = USDataCenter::PRODUCTION();
$token = (new OAuthBuilder())
    ->clientId("1000.CLIENT_ID")
    ->clientSecret("secr")
    ->grantToken('1000.portal_token')

    ->build();

$tokenstore = new FileStore("/tokens/data/token.txt");

$autoRefreshFields = false;
$pickListValidation = false;
$connectionTimeout = 10;
$timeout = 10;
$enableSSLVerification = false;
$configInstance = (new SDKConfigBuilder())
    ->autoRefreshFields($autoRefreshFields)
    ->pickListValidation($pickListValidation)
    ->sslVerification($enableSSLVerification)
    ->connectionTimeout($connectionTimeout)
    ->timeout($timeout)->build();
$user = new UserSignature('owner@gmail.com');
$sdk = (new InitializeBuilder());
$sdk->environment($environment)
    ->token($token)
    ->store($tokenstore)
    ->user($user)
    ->SDKConfig($configInstance)
    ->initialize();

//$token->refreshAccessToken($user, $tokenstore);

$query = "select Email from Contacts where Email = 'client@gmail.com'";

$queryOperations = new QueryOperations();
// Create a new BodyWrapper instance to set the query
$bodyWrapper = new BodyWrapper();
// Set the select query in the body wrapper
$bodyWrapper->setSelectQuery($query);
// Execute the query and get the response
$response = $queryOperations->getRecords($bodyWrapper);

if ($response != null) {
    echo("Status Code: XXX" . $response->getStatusCode() . "\n");
    if ($response->isExpected()) {
        $responseHandler = $response->getObject();
        if ($responseHandler instanceof ResponseWrapper) {
            $responseWrapper = $responseHandler;
            $records = $responseWrapper->getData();
            foreach ($records as $record) {
                echo("Record ID: " . $record->getId() . "\n");
                $createdBy = $record->getCreatedBy();
                if ($createdBy != null) {
                    echo("Record Created By User-ID: " . $createdBy->getId() . "\n");
                    echo("Record Created By User-Name: " . $createdBy->getName() . "\n");
                    echo("Record Created By User-Email: " . $createdBy->getEmail() . "\n");
                }
                echo("Record CreatedTime: " . $record->getCreatedTime() . "\n");
                $modifiedBy = $record->getModifiedBy();
                if ($modifiedBy != null) {
                    echo("Record Modified By User-ID: " . $modifiedBy->getId() . "\n");
                    echo("Record Modified By User-Name: " . $modifiedBy->getName() . "\n");
                    echo("Record Modified By User-Email: " . $modifiedBy->getEmail() . "\n");
                }
                echo("Record ModifiedTime: " . $record->getModifiedTime() . "\n");
                echo("Record Field Value: " . $record->getKeyValue("Last_Name") . "\n"); // FieldApiName
                echo("Record KeyValues: \n");
                foreach ($record->getKeyValues() as $keyName => $value) {
                    if ($value != null) {
                        if ((is_array($value) && sizeof($value) > 0) && isset($value[0])) {
                            echo("Record KeyName : " . $keyName . "\n");
                            $dataList = $value;
                            foreach ($dataList as $data) {
                                if (is_array($data)) {
                                    echo("Record KeyName : " . $keyName . " - Value :  \n");
                                    foreach ($data as $key => $arrayValue) {
                                        echo($key . " : " . $arrayValue);
                                    }
                                } else {
                                    print_r($data);
                                    echo("\n");
                                }
                            }
                        } else {
                            echo("Record KeyName : " . $keyName . " - Value : " . print_r($value));
                            echo("\n");
                        }
                    }
                }
            }
            $info = $responseWrapper->getInfo();
            if ($info != null) {
                if ($info->getCount() != null) {
                    echo("Record Info Count: " . $info->getCount() . "\n");
                }
                if ($info->getMoreRecords() != null) {
                    echo("Record Info MoreRecords: " . $info->getMoreRecords() . "\n");
                }
            }
        } else if ($responseHandler instanceof APIException) {
            $exception = $responseHandler;
            echo("Status: " . $exception->getStatus()->getValue() . "\n");
            echo("Code: " . $exception->getCode()->getValue() . "\n");
            echo("Details: ");
            if ($exception->getDetails() != null) {
                echo("Details: \n");
                foreach ($exception->getDetails() as $keyName => $keyValue) {
                    echo($keyName . ": " . $keyValue . "\n");
                }
            }
            echo("Message : " . ($exception->getMessage() instanceof Choice ? $exception->getMessage()->getValue() : $exception->getMessage()) . "\n");

            var_dump($exception);
        }
    } else {
        print_r($response);
    }
}

?>

    Zoho Developer Community






                              Zoho Desk Resources

                              • Desk Community Learning Series


                              • Digest


                              • Functions


                              • Meetups


                              • Kbase


                              • Resources


                              • Glossary


                              • Desk Marketplace


                              • MVP Corner


                              • Word of the Day



                                  Zoho Marketing Automation


                                          Manage your brands on social media



                                                Zoho TeamInbox Resources

                                                  Zoho DataPrep Resources



                                                    Zoho CRM Plus Resources

                                                      Zoho Books Resources


                                                        Zoho Subscriptions Resources

                                                          Zoho Projects Resources


                                                            Zoho Sprints Resources


                                                              Qntrl Resources


                                                                Zoho Creator Resources


                                                                  Zoho WorkDrive Resources



                                                                    Zoho Campaigns Resources

                                                                      Zoho CRM Resources

                                                                      • CRM Community Learning Series

                                                                        CRM Community Learning Series


                                                                      • Tips

                                                                        Tips

                                                                      • Functions

                                                                        Functions

                                                                      • Meetups

                                                                        Meetups

                                                                      • Kbase

                                                                        Kbase

                                                                      • Resources

                                                                        Resources

                                                                      • Digest

                                                                        Digest

                                                                      • CRM Marketplace

                                                                        CRM Marketplace

                                                                      • MVP Corner

                                                                        MVP Corner

                                                                      





                                                                      




                                                                          Design. Discuss. Deliver.

                                                                          Create visually engaging stories with Zoho Show.

                                                                          Get Started Now