0

OAuth for Googleで少し問題が発生しました。CodeIgniter(http://codeigniter.com/wiki/OAuth_for_Google)にJim Saunder Libraireを使用していますが、access_youtube関数にアクセスすると次のようになります。

public function access_youtube()
{ //STEP 2

// Here is the first call to load the library 
    $params['key'] = 's390075769.onlinehome.fr';
    $params['secret'] = 'iHD72YKzWmbm8VTwncht_E-d';

// We  can change the signing algorithm and http method by setting the following in your params array.
    $params['algorithm'] = 'HMAC-SHA1';
    // $params['method'] = "GET";

// We need to reload the library since we left our site beetween Step 1 & 2.
    $this->load->library('google_oauth', $params);

// We are using HMAC signing you need to specify the token_secret you got from the request step as the second parameter of this method. So
    $token_secret = $this->session->userdata('token_secret');
    $oauth = $this->google_oauth->get_access_token(false, $token_secret);

// The access method will return an array with keys of ‘oauth_token’, and ‘oauth_token_secret’ 
// These values are your access token and your access token secret. We should store these in our database.  
    $this->session->set_userdata('oauth_token', $oauth['oauth_token']);
    $this->session->set_userdata('oauth_token_secret', $oauth['oauth_token_secret']);

// Now you have an access token and can make google service requests on your users behalf
    redirect(site_url());
}

いくつかのエラーメッセージが表示されました:

未定義のインデックス:oauth_token

未定義のインデックス:oauth_token_secret

$ this-> session->set_userdata..の行を参照します。

そして、各エラーメッセージの後に私は得る:

メッセージ:ヘッダー情報を変更できません-ヘッダーは既に送信されています(出力は/homepages/7/d390075755/htdocs/system/core/Exceptions.php:170で開始されました)ファイル名:libraries / Session.php行番号:671

これは、前のエラーメッセージに関連していると思います。

だから私はコンストラクターでそれを試しました:

class Example extends CI_Controller
{
private $CI;
public function __construct()
{
     parent::__construct();

    $this->CI =& get_instance();
    $this->CI->load->library('session');

    $oauth = array();
    $oauth['oauth_token_secret']='';
    $oauth['oauth_token']='';

}

私の関数の直前ですが、それは何もしません..そして私はグーグルによって私のセッション変数の在庫を失うことになるのではないかと心配しています...そうではありませんか?Googleからトークンを取得しますか?

4

1 に答える 1

1

正直なところ、セッションがPHPコードによってどのように管理されるかはわかりませんので、ほとんど役に立ちません。この線が原因のようです

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

あなたはGoogleからaccess_tokenを取得して、アプリケーションを承認したユーザー情報を取得するためにGoogle APIにリクエストを送信しようとしていますが、Googleはそれらから期待されたものを返していないと思います。これは、Google Oauthがあなたに期待しているものと、実際に送信しているものとして、リクエストデータのタイプの不一致が原因である可能性があります

あなたの場合、私はEclipseのデバッガーを使用して、正確に何が起こっているのかを確認していましたが、OAuthの場合は、以前の質問ですでに説明しました

  1. 最初のステップで取得したトークンを保存する必要があります。
  2. ユーザーが認証から戻ったら、そのリクエストトークンを使用してaccess_tokenを取得する必要があります
  3. リクエストトークンを取得したら、最終的なAPI呼び出しを行う準備ができており、コードがセッションからデータを取得できていないようです。
于 2011-12-08T09:53:37.970 に答える