简体   繁体   English

PHP卷曲与shopify输出中的麻烦

[英]Php Curl with shopify trouble in output

So basically I just grab a code from here and test run it. 所以基本上我只是从这里获取代码并测试运行它。

This is the code: 这是代码:

<?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);

?>

and i get this 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_...

all I need Is just the last line, And I just don't know how to remove the other lines. 我需要的只是最后一行,而我只是不知道如何删除其他行。 This tutorial here http://www.codefixup.com/create-app-and-getting-started-with-shopify-api-in-php/ just shows how to connect with the shopify but doesn't says how. 本教程位于http://www.codefixup.com/create-app-and-getting-started-with-shopify-api-in-php/中,仅显示了如何与shopify连接,但未说明如何连接。 Can anyone help me. 谁能帮我。 Sorry for bad English. 对不起,英语不好。

The best way is to use some OOP Wrapper like this one 最好的方法是使用像这样的一些OOP包装器

It give's you more control on curl request (headers, body, status code) 它使您可以更好地控制卷曲请求(标题,正文,状态码)

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

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

Just comment out this line 只需注释掉这一行

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

This was the headers lines you get. 这是您获得的标题行。

You can also try this one it is workign for me 您也可以尝试这个对我来说很有用

<?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;
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM