2

google-php-clientの例では、ユーザーがリンクをクリックしたときに認証URLを呼び出します。ユーザーがクリックせずにページが読み込まれたときに呼び出したいと思います。google-clientの例で実装する方法:

$client = new Google_Client();
$client->setApplicationName('Google Contacts PHP Sample');
$client->setScopes("http://www.google.com/m8/feeds/");
$auth = $client->createAuthUrl();
print "<a class=login href='$auth'>Connect Me!</a>";

Connect Meリンクをクリックして、で指定されたurlを呼び出すことへの依存を削除しようとしてい$client->createAuthUrl()ます。私はCodeigniterを初めて使用するため、この単純なタスクに苦労しています。
URLを呼び出すには、次のさまざまな方法があることを確認しましたが、どちらがここで機能するかはわかりません。

  1. カール
  2. file_get_contents
  3. stream_context_create

XAMPPでphp5.3を使用しています

4

3 に答える 3

2

CodeIgniterのライブラリを使用した単純なリダイレクトには、以下を使用します。

$client = new Google_Client();
$client->setApplicationName('Google Contacts PHP Sample');
$client->setScopes("http://www.google.com/m8/feeds/");
$auth = $client->createAuthUrl();

$this->load->helper('url');
redirect($auth); // Returns a HTTP redirect to the client

header('Location: ... ');これは、 2番目のパラメーターが渡されない(またはとして渡される)場合のラッパー'location'です。

于 2013-01-26T23:55:23.513 に答える
1

URLヘルパーまたは代替からのリダイレクトを使用するだけです:

echo '<script>window.location = "'.$your_location.'"</script>';
于 2013-01-26T23:49:33.147 に答える
0

php関数を使用してください!

header('Location: $auth', TRUE, 301);

Codeigniterについて話しているので、組み込みのredirect()を使用する方が適切です。

 //loading the helper
 $this->load->helper('url');
 redirect($auth);

CodeigniterURLヘルパーの詳細

于 2013-01-26T23:49:09.810 に答える