Php Curl与输出中的shopify麻烦

时间:2017-02-21 09:28:19

标签: php curl shopify

所以基本上我只是从here获取代码并测试运行它。

这是代码:

<?php

$url = "https://230******************dc20:b0817***************008@tr*********s.myshopify.com/admin/customers.json";

$shopcurl = curl_init();
curl_setopt($shopcurl, CURLOPT_URL, $url);
curl_setopt($shopcurl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($shopcurl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($shopcurl, CURLOPT_VERBOSE, 0);
curl_setopt($shopcurl, CURLOPT_HEADER, 1);
curl_setopt($shopcurl, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($shopcurl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec ($shopcurl);
curl_close ($shopcurl);
echo "<pre>";
print_r($response);

?>

我得到了这个回复:

HTTP/1.1 200 OK
Server: nginx
Date: Tue, 21 Feb 2017 09:24:50 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Vary: Accept-Encoding
X-Frame-Options: DENY
X-ShopId: 17203005
X-ShardId: 4
X-Shopify-Shop-Api-Call-Limit: 1/40
HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT: 1/40
X-Stats-UserId: 0
X-Stats-ApiClientId: 1529067
X-Stats-ApiPermissionId: 40137419
X-Request-Id: cc57cc1a-da08-4460-bb34-53733b411c6d
Content-Security-Policy: default-src 'self' https://* shopify-pos://*;
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Permitted-Cross-Domain-Policies: none
X-XSS-Protection: 1; mode=block; report=/xss-report?source%5Baction%5D=index&sour
P3P: CP="NOI DSP COR NID ADMa OPTa OUR NOR"
X-Dc: ash
X-Content-Type-Options: nosniff

{"orders":[{"id":4243430853,"email":"jayduco2@gmail.com","closed_at":null,"created_at":"2017-01-31T11:11:05+08:00","updated_...

我需要的只是最后一行,而我只是不知道如何删除其他行。 本教程http://www.codefixup.com/create-app-and-getting-started-with-shopify-api-in-php/仅显示了如何与shopify联系,但没有说明如何。谁能帮我。抱歉英语不好。

3 个答案:

答案 0 :(得分:0)

最好的方法是使用像this one

这样的OOP包装器

它让您更好地控制卷曲请求(标题,正文,状态代码)

$curl = new Curl\Curl();
$curl->get($url);

if ($curl->error) {
    echo $curl->error_code;
}
else {
    echo $curl->response;
}

答案 1 :(得分:0)

只需注释掉这一行

//curl_setopt($shopcurl, CURLOPT_HEADER, 1);

这是你得到的标题行。

答案 2 :(得分:0)

你也可以尝试这个适合我的工作

<?php header('Access-Control-Allow-Origin: *');
  header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
$getpage_id=$_REQUEST['page_id']?$_REQUEST['page_id']:"1";

$curl_url="https://71efdddxxxxxxxx:69c64xxxxxxxxx@myshop.myshopify.com/admin/products.json?limit=250&page=".$getpage_id;

$s=file_get_contents($curl_url);
echo $s;
?>