使用 PHP 访问(非公开)Google 协作平台页面

发布于 2024-12-16 11:26:01 字数 143 浏览 9 评论 0原文

我正在尝试阅读非公开 Google 网站页面的内容。我编写了用于读取公共 Google 站点页面的 php 脚本,因此它使用 php 的 file_get_content()。

有没有办法登录 php 脚本以便能够访问非公开的 Google 协作平台页面?

i am trying to read the content of a non-public Google Site Page. I wrote the php Script for reading a public Google Sites Page, so it is using php's file_get_content().

Is there a way to login the php script so it is able to access the non public Google Sites Page?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

与酒说心事 2024-12-23 11:26:01

找到一些执行类似操作的旧代码。应该让你开始

/* Prepare cURL */
$ch = curl_init();  

// set these according to the login form
$login_query = http_build_query(
                    array('username'=> 'username',
                        'password' => 'your_password',
                        'login' => 'log in'));

/* Set options */
curl_setopt($ch, CURLOPT_URL, 'www.yourpage.com');
curl_setopt($ch, CURLOPT_REFERER, 'www.yourpage.com'); //set this to whatever the normal login does
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3'); //set to something resonable
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies/cookie.txt'); // make sure directory is writable
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies/cookie.txt');
curl_setopt($ch, CURLOPT_POSTFIELDS, $login_query);
curl_setopt($ch, CURLOPT_POST, 1);

$urlcontent = utf8_encode(curl_exec($ch));
$curl_info = curl_getinfo($ch);

// at this point you are logged in... get your page

/* Initiate cURL request */
curl_setopt($ch, CURLOPT_URL, 'www.yourpage.com/what-you-want');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3');
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_REFERER, 'www.yourpage.com');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies/cookie.txt');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

/* Send cURL request */
$result_data = utf8_encode(curl_exec($ch));
$curl_info = curl_getinfo($ch);

/* Close cURL */
curl_close($ch);

/* Handle result if any */
if ($this->curl_info['http_code'] == 200)
{
    // at this point your page is in $result_data
}

Found some old code that does something similar. Should get you started

/* Prepare cURL */
$ch = curl_init();  

// set these according to the login form
$login_query = http_build_query(
                    array('username'=> 'username',
                        'password' => 'your_password',
                        'login' => 'log in'));

/* Set options */
curl_setopt($ch, CURLOPT_URL, 'www.yourpage.com');
curl_setopt($ch, CURLOPT_REFERER, 'www.yourpage.com'); //set this to whatever the normal login does
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3'); //set to something resonable
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies/cookie.txt'); // make sure directory is writable
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies/cookie.txt');
curl_setopt($ch, CURLOPT_POSTFIELDS, $login_query);
curl_setopt($ch, CURLOPT_POST, 1);

$urlcontent = utf8_encode(curl_exec($ch));
$curl_info = curl_getinfo($ch);

// at this point you are logged in... get your page

/* Initiate cURL request */
curl_setopt($ch, CURLOPT_URL, 'www.yourpage.com/what-you-want');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3');
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_REFERER, 'www.yourpage.com');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies/cookie.txt');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

/* Send cURL request */
$result_data = utf8_encode(curl_exec($ch));
$curl_info = curl_getinfo($ch);

/* Close cURL */
curl_close($ch);

/* Handle result if any */
if ($this->curl_info['http_code'] == 200)
{
    // at this point your page is in $result_data
}
写给空气的情书 2024-12-23 11:26:01

如果您想访问需要某种帖子、会话或任何内容的页面,我建议您使用 CURL 而不是 file_get_contents。您可以在文档上阅读更多相关信息。

我不确定它是否适用于谷歌非公开页面。但这可能会变成一个巨大的挑战:-)

If you want to access a page that requires some sort of posts, sessions or anything, i'd suggest you to use CURL instead of file_get_contents. You can read more about it on the documentation.

If it will work for googles non-public pages, im unsure of. It can turn into a great challenge though :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文