私は以下の構造を持つこのアプリケーションを持っています
レスト クライアント ライブラリ https://github.com/philsturgeon/codeigniter-restclientを使用してMyAPI に接続し、 php API クライアント http://code.google.com/p/google-api-php-client/を使用して接続していますGoogle APIへ
私のコントローラーコードは以下の通りです
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);
}
このリクエストを処理するAPIコードは以下のとおりで、ユーザーがデータベースに存在し、Googleでも認証されていることを確認します
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);
}
Google
ライブラリ関数「Authenticate」は次のとおりです
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);
}
}
問題は
、このThroughtブラウザを直接URLに接続すると、
http://localhost/hac_dc/api/auth/user/ahmed.samy.cs@gmail.com
JSON応答が完全に得られることです
しかし、残りのクライアントを使用して接続すると
私は応答を受け取りfalse
ました。残りのクライアントの使用方法を変更しようとしました。第 3 パラメーターを MIME としてJSON
、および MIMEとして追加しようとしましapplication/json
たが、うまくいきませんでした。
私のREST APIを介して別のREST APIを接続することが問題なのか悪い習慣なのかはわかりませんが、
何時間も髪を引っ張っていたので助けてください