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
链接并调用 $client->createAuthUrl()
给出的 url 的依赖。我是 Codeigniter 的新手,这就是为什么在这个简单的任务上苦苦挣扎。
我检查了是否有以下不同的方法来调用 URL,但不确定哪一种可以在这里使用:
- curl
- 文件获取内容
- stream_context_create
我正在使用 php 5.3 和 XAMPP
最佳答案
要使用 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
当没有传递第二个参数(或作为 'location'
传递)时,这是 header('Location: ... ');
的包装器。
关于php - Codeigniter:从 View 页面重定向到另一个 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14542770/