Connecting Google REST APIs through my REST API does not work

I have this application with the structure below enter image description here

I use the leisure client library https://github.com/philsturgeon/codeigniter-restclient to connect to MyAPI and using the php api client http://code.google.com/p/google-api-php-client/ to connect to google API

my controller code is below

 function index()
    {
        if($this->form_validation->run())
        {
           $logged = $this->rest->get('auth/user',array(
               'email'=>$this->input->post('email')
                   )); 
           var_dump($logged);
        }
        $this->load->view('layout/login',$this->data);
    }

and my API code that processes this request is below to make sure the user exists in my database and is authenticated through Google, as well

function user_get()
    {
        $response=NULL;
        $data=array(
            'email'=>$this->get('email')
        );
        $google_account=$this->google->authenticate();
        if(  isset($google_account) && $this->user_model->login($data))
        {
            $response->status='success';
            $response->message=$google_account;
        }
        else
        {
            $response->status='error';
            $response->message='Failed to authenticate user';   
        }
        $this->response($response,200);
    }

and the Googlelibrary function `Authenticate 'is below

function authenticate()
    {
        $oauth2 = new Google_Oauth2Service($this->client);
        if (isset($_GET['code']))
        {
            $this->client->authenticate($_GET['code']);
            $_SESSION['token'] = $this->client->getAccessToken();
            $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
            header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
            return;
        }
        if (isset($_SESSION['token'])) 
        {
            $this->client->setAccessToken($_SESSION['token']);
        }
        if (isset($_REQUEST['logout'])) 
        {
            unset($_SESSION['token']);
            $this->client->revokeToken();
        }
        if ($this->client->getAccessToken()) 
        {
            $user = $oauth2->userinfo->get();
            // The access token may have been updated lazily.
            $_SESSION['token'] = $this->client->getAccessToken();
            return $user;
        } 
        else 
        {
            $authUrl = $this->client->createAuthUrl();
            redirect($authUrl);
        }

    }

URL- http://localhost/hac_dc/api/auth/user/ahmed.samy.cs@gmail.com JSON

i get response false . JSON MIME application/json,

, REST API, REST API,

, ,

+5
2

REST oauth, ? , REST, , Google.

, , Google, API (, , ). , REST.

REST Google cURL - , https://github.com/philsturgeon/codeigniter-oauth2.git. REST API, / HTTP ( CodeIgniter-REST) ​​ api ( ).

P.S. 401 (. http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.2)

+5

- .

localhost/hac_dc/api/auth/user/ahmed.samy.cs@gmail.com

-. REST getJSON. JSONP jquery ajax, 100% . JSONP JSON, js JSON. ajax. JSONP "" , ajax- .

$.ajax({
       crossDomain: true,
       type:"GET",
       contentType: "text; charset=utf-8",
       url: YOUR_URL + "&callback=mycallback",
        jsonp:'jsonp',
       dataType: "jsonp"
       });
function mycallback(result){
    //your callback operation
}
0

All Articles