我如何卷曲深爬行? [英] How can I curl deepcrawl?

查看:97
本文介绍了我如何卷曲深爬行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Deepcrawl抓取仅提供空值.

My Deepcrawl crawl only give null value.

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"https://api.deepcrawl.com/accounts/00000/projects/195334/crawls/1306396/reports/thin_pages_basic");

curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch,CURLOPT_HTTPHEADER,array('X-Auth-Token:Private'));

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output2 = curl_exec ($ch);
curl_close ($ch); 

$results = json_decode($server_output2);

要创建会话,您首先需要手动生成一个API密钥.这是可以在"API访问"页面中生成的键/值对.当您单击生成新的API密钥"时,将显示一个弹出窗口,其中包含API密钥值,并且在活动密钥"表中可以找到API密钥ID.然后通过POST调用中的基本身份验证将其发送到会话路由.

To create a session you first need to manually generate an API Key. This is a key/value pair that can be generated in the API Access page. When you click Generate New API Key, a popup will be displayed with the API Key Value and in the table of Active Keys you can find the API Key ID. This is then sent via Basic Authentication in a POST call to the sessions route.

curl -X POST -u '123:abcdef' https://api.deepcrawl.com/sessions
{
"token":"abcdef123",
"_user_href":"/users/example-user",
...
}

从会话调用返回的令牌然后作为X-Auth-Token标头传递到所有API调用:

The token returned from the call to sessions is then passed to all API calls as the X-Auth-Token header:

curl -X GET -H 'X-Auth-Token:' https://api.deepcrawl.com/accounts/1/projects

有人可以进一步向我解释有关Deepcrawl的身份验证吗?如何仅使用X-Auth-Token可以卷曲它.对不起,我的英语不好.谢谢

Can someone explain me further about the authentication of deepcrawl? How can I able to curl it using X-Auth-Token only. Sorry for my bad English. Thank you

推荐答案

CURL有时可能很棘手.

CURL may be tricky sometimes.

当我遇到CURL问题时,我首先尝试在命令行上执行相同的操作,在这种情况下,它工作得很好,因此我们可以拒绝API或CURL上的任何类型的问题,因此我们必须假定问题出在php调用.

When I face problems with CURL I first try to do the same on command line, in this case it worked perfectly so we can reject there is any kind of problem on API or on CURL so we must assume the problem is on the php call.

当您获得NULL时,很可能在curl处理程序上设置了错误,您只需要查找它并将其显示在屏幕上即可:

When you get a NULL it's likely there is an error set on curl handler, you just need to look for it and bring it to screen:

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL,"https://api.deepcrawl.com/accounts/00000/projects/195334/crawls/1306396/reports/thin_pages_basic");

    curl_setopt($ch, CURLOPT_POST, 0);
    curl_setopt($ch,CURLOPT_HTTPHEADER,array('X-Auth-Token:Private'));

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $server_output2 = curl_exec ($ch);

    if (curl_errno($ch)) {
        print curl_error($ch);
        die();
        // or whatever you might want to do with this error
       } 
    curl_close ($ch); 

    $results = json_decode($server_output2);

在这种情况下,错误是:

In this case the error was:

SSL证书问题:无法获取本地颁发者证书

SSL certificate problem: unable to get local issuer certificate

此处,您可以查看如何解决此问题,只需将有效的CA证书添加到您的php.ini中(在示例中使用cacert),如下所示:

Here you can see how to fix this problem, just need to add a valid CA cert to your php.ini (in the example cacert is used) like that:

1)从 https://curl.haxx.se/下载最新的cacert.pem. ca/cacert.pem

2)将以下行添加到php.ini中(如果这是共享主机,并且您无权访问php.ini,则可以将其添加到public_html中的.user.ini中)

2) Add the following line to php.ini (if this is shared hosting and you don't have access to php.ini then you could add this to .user.ini in public_html)

curl.cainfo ="/path/to/downloaded/cacert.pem"

curl.cainfo="/path/to/downloaded/cacert.pem"

这篇关于我如何卷曲深爬行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆