rest api login akun google

 <?php
   public function create_google(){
		include_once APPPATH .'third_party/google-api-client/Google_Client.php';
        include_once APPPATH .'third_party/google-api-client/contrib/Google_Oauth2Service.php';

		$clientId = 'client id';
		$clientSecret = 'client secret';
		$redirectUrl = base_url() . 'a/';

		$gClient = new Google_Client();
        $gClient->setApplicationName('Login ke Aplikasi');
        $gClient->setClientId($clientId);
        $gClient->setClientSecret($clientSecret);
        $gClient->setRedirectUri($redirectUrl);
        $google_oauthV2 = new Google_Oauth2Service($gClient);
		if (isset($_REQUEST['code'])) {
			$gClient->authenticate();
			$this->session->set_userdata('token', $gClient->getAccessToken());
			redirect($redirectUrl);
		}
		$token = $this->session->userdata('token');
		if (!empty($token)) {
			$gClient->setAccessToken($token);
		}
		if ($gClient->getAccessToken()) {
			$userProfile = $google_oauthV2->userinfo->get();
			$userData['oauth_provider'] = 'google';
			$userData['oauth_uid'] = $userProfile['id'];
			$userData['first_name'] = $userProfile['given_name'];
			$userData['last_name'] = $userProfile['family_name'];
			$userData['email'] = $userProfile['email'];
			$userData['gender'] = $userProfile['gender'];
			$userData['locale'] = $userProfile['locale'];
			$userData['profile_url'] = $userProfile['link'];
			$userData['picture_url'] = $userProfile['picture'];
			$resp = $this->m_user->user_create_data($userData);
			if($resp['errorCode']  == 200){
				 $stat = "SUCCESS";
			}else{
			  $stat = "ERROR";
			}
	        $count = array($resp);
	        $jsonAr = array(
	        	"_meta" => array('status' => $stat,'count' => count($count)),
	            "result" => $resp
	        );
	        json_output($resp['errorCode'],$jsonAr);
        } else {
            return $this->$gClient->createAuthUrl();
        }
  		$jsonAr = array(
		    "_meta" => array('Status' => 'SUCCESS','count' => 1),
		    "result" => array('errorCode' => 200,'userMessage' => 'Successfully')
		);
		json_output(200,$jsonAr);
    }

error A PHP Error was encountered Severity: 4096

Message: Object of class Google_Client could not be converted to string

Filename: v1/User.php

Line Number: 662

Backtrace:

File: C:\xampp\htdocs\api-v8\application\controllers\v1\User.php Line: 662 Function: _error_handler

File: C:\xampp\htdocs\api-v8\index.php Line: 315 Function: require_once

sore semuannya, udah stak nih salahnya di sini return $this->$gClient->createAuthUrl(); yang bener seharusnya gmana ya cara akses nya?????????

avatar abdulrojakUG
@abdulrojakUG

59 Kontribusi 0 Poin

Diperbarui 6 tahun yang lalu

1 Jawaban:

boleh liat siapa yg panggil fungsi create_google() nya gan?

kalo diliat dari sini:


return $this->$gClient->createAuthUrl();
//Message: Object of class Google_Client could not be converted to string

ini karena Object dari create_google() tidak bisa return nya String gan coba ubah return nya jadi object Google_Client juga gan

avatar keccikun
@keccikun

364 Kontribusi 196 Poin

Dipost 6 tahun yang lalu

Login untuk ikut Jawaban