3

私は現在、Google API を介してユーザーのログインを許可する私のサイトの OAuth 認証システムに取り組んでいます。

Codeigniter 2.0.2 を使用していますが、サーバーで PECL OAuth をコンパイルしていないため、生の php を使用してこれを行う必要があります。

Google でユーザーを認証し、そのユーザーのoauth_tokenoauth_token_secretを取得しました。

しかし、プロトコルを無限に読んだ後でも、そのoauth_keyoauth_token_secretが他の API にアクセスして次の情報を収集する方法を見つけることができません。

  • 電子メールアドレス
  • プロフィールの写真
  • フルネーム
  • 位置

認証に使用している現在のコードは次のとおりです。

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class OAuth extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();

        $this->load->library('google_oauth',array(
            'key'       => '*REMOVED*',
            'secret'    => '*REMOVED*',
            'algorithm' => 'HMAC-SHA1'
        ));
    }

    public function login()
    {
        //Get Request Token
        $response = $this->google_oauth->get_request_token(
            site_url("/oauth/collect"),
            'http://www.google.com/m8/feeds/'
        );

        //Store temp
        $this->session->set_flashdata('g.token.secret', $response['token_secret']);

        //Redirect
        redirect($response['redirect']);
    }

    public function collect()
    {
        $token_s = $this->session->flashdata('g.token.secret');
        if(!$token_s)
        {
            $this->session->set_flashdata('error','Invalid auth session data, please rety your login');
            redirect();
        }

        $oauth = $this->google_oauth->get_access_token(false, $token_s);

        /*Check the data is valid*/
        if(!isset($oauth['oauth_token']) || !isset($oauth['oauth_token_secret']))
        {
            $this->session->set_flashdata('error','Unable to authecticate securly with Google, please try again');
            redirect();
        }

        $token = $oauth['oauth_token'];
        $secret = $oauth['oauth_token_secret'];

        //Will Store Here
    }
}

そして、現在、この認証クラスのわずかに変更されたバージョンを使用しています:

https://github.com/jimdoescode/CodeIgniter-YouTube-API-Library/blob/master/application/libraries/google_oauth.php

4

1 に答える 1

2

Google OAuth Playgroundを試してみましたか? アクセスできる API フィードを特定し、有効なリクエスト文字列を作成するのに役立ちます。

アクセスできる Google API のリストは次のとおりです: Google API ディレクトリ

それが役立つことを願っています

于 2011-08-26T07:47:39.783 に答える