asciisd / zoho

Zoho package for Laravel
36 stars 36 forks source link

No Tokens exist for the given user-identifier,Please generate and try again #2

Closed izorwebid closed 4 years ago

izorwebid commented 4 years ago

I get an error like this

No Tokens exist for the given user-identifier,Please generate and try again

i use this code

public function zohoLead()
    {
        $module = \Asciisd\Zoho\Facades\Zoho::useModule('leads');
        dd($module->getRecords());
    }

or i must invoke ?

ZCRMRestClient::initialize($configuration);

before, i use this code and success

public function __construtc() {
//configuration here
}

public function zohoLead()
{
    $client = new RestClient(ZCRMRestClient::getInstance())
    $module = $client->useModule('leads');
    $records = $module->getRecords();
}
aemaddin commented 4 years ago

No there is no need to revoke the initialize method if you are using the Facade Class, Service Provider do it for you,

I think this error mean that the email address you are using is not the same that you are using on Zoho crm

I've tried same code you are using and work fine for me

make sure to set ZOHO_CURRENT_USER_EMAIL on .env file with correct email address

izorwebid commented 4 years ago

i know why i always getting error, I think this is a bug, you hardcode your mail in ZohoServiceProvider

private function registerSingleton()
    {
        $this->app->singleton('zoho', function ($app) {
            $configuration = [
                'client_id' => config('zoho.client_id'),
                'client_secret' => config('zoho.client_secret'),
                'redirect_uri' => config('zoho.redirect_uri'),
                'currentUserEmail' => 'it@caveo-kw.com',  <------ this your email?
                'applicationLogFilePath' => config('zoho.application_log_file_path'),
                'token_persistence_path' => config('zoho.token_persistence_path'),
                'accounts_url' => config('zoho.accounts_url'),
                'sandbox' => config('zoho.sandbox'),
                'apiBaseUrl' => config('zoho.api_base_url'),
                'apiVersion' => config('zoho.api_version'),
                'access_type' => config('zoho.access_type'),
                'persistence_handler_class' => config('zoho.persistence_handler_class'),
            ];

            ZCRMRestClient::initialize($configuration);
            return new RestClient(ZCRMRestClient::getInstance());
        });
    }

i change to this and work

private function registerSingleton()
    {
        $this->app->singleton('zoho', function ($app) {
            $configuration = [
                'client_id' => config('zoho.client_id'),
                'client_secret' => config('zoho.client_secret'),
                'redirect_uri' => config('zoho.redirect_uri'),
                'currentUserEmail' => config('zoho.current_user_email'),
                'applicationLogFilePath' => config('zoho.application_log_file_path'),
                'token_persistence_path' => config('zoho.token_persistence_path'),
                'accounts_url' => config('zoho.accounts_url'),
                'sandbox' => config('zoho.sandbox'),
                'apiBaseUrl' => config('zoho.api_base_url'),
                'apiVersion' => config('zoho.api_version'),
                'access_type' => config('zoho.access_type'),
                'persistence_handler_class' => config('zoho.persistence_handler_class'),
            ];

            ZCRMRestClient::initialize($configuration);
            return new RestClient(ZCRMRestClient::getInstance());
        });
    }
ghost commented 4 years ago

Yep 😅, Sorry for that and thanks for PR.