Welcome Guest, Not a member yet? Register   Sign In
google index api integration
#5

y change the code a little bit

this is my indexing model
PHP Code:
<?php  if (! defined('BASEPATH')) {
    exit('No direct script access allowed');
}

class Indexing extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
    }
    
    public function AddUrl($url)
    {
        require APPPATH . 'libraries/google/vendor/autoload.php';
        $client = new Google_Client();

        $client->setAuthConfig(APPPATH . 'xxxxxxxxxxxxxxxxx.json');
        $client->addScope('https://www.googleapis.com/auth/indexing');
    
        $httpClient = $client->authorize();
        $endpoint = 'https://indexing.googleapis.com/v3/urlNotifications:publish';
    
        $content = '{
          "url": "' . $url . '",
          "type": "URL_UPDATED"
        }';
    
        $response = $httpClient->post($endpoint, [ 'body' => $content ]);
        $status_code = $response->getStatusCode();

        return $status_code;
    }

    public function DelUrl($url)
    {
        require APPPATH . 'libraries/google/vendor/autoload.php';
        $client = new Google_Client();

        $client->setAuthConfig(APPPATH . 'xxxxxxxxxxxxxxxxx.json');
        $client->addScope('https://www.googleapis.com/auth/indexing');
    
        $httpClient = $client->authorize();
        $endpoint = 'https://indexing.googleapis.com/v3/urlNotifications:publish';
    
        $content = '{
          "url": "' . $url . '",
          "type": "URL_DELETED"
        }';
    
        $response = $httpClient->post($endpoint, [ 'body' => $content ]);
        $status_code = $response->getStatusCode();
        
        return $status_code;
    }

    public function StatusUrl($url)
    {
        require APPPATH . 'libraries/google/vendor/autoload.php';
        $client = new Google_Client();

        $client->setAuthConfig(APPPATH . 'xxxxxxxxxxxxxxxxx.json');
        $client->addScope('https://www.googleapis.com/auth/indexing');
    
        $httpClient = $client->authorize();
        $endpoint = 'https://indexing.googleapis.com/v3/urlNotifications/metadata?url=' . $url;
    
        $response = $httpClient->get($endpoint);
        $status_code = $response->getStatusCode();
        
        return $status_code;
    }



and this is the code i added in my controller

PHP Code:
$this->load->model('Indexing');
$url base_url('xxxxxxxxxxxx');
$response $this->Indexing->addUrl($url); 
Reply


Messages In This Thread
google index api integration - by maverik23 - 05-08-2020, 12:38 PM
RE: google index api integration - by jreklund - 05-08-2020, 12:46 PM
RE: google index api integration - by maverik23 - 05-08-2020, 01:14 PM
RE: google index api integration - by jreklund - 05-08-2020, 01:23 PM
RE: google index api integration - by maverik23 - 05-08-2020, 05:27 PM



Theme © iAndrew 2016 - Forum software by © MyBB