Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Integracja z API SendOwl
m-mike
post 4.05.2018, 20:09:09
Post #1





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 8.09.2010

Ostrzeżenie: (0%)
-----


Cześć
Mam taki kod:
  1. <?php
  2.  
  3. $key = 'xxxxx'; // my own
  4. $secret = 'yyyyy'; // my own
  5. $url = 'https://' . $key . ':' . $secret . '@www.sendowl.com/api/v1/products/';
  6. $ch = curl_init($url);
  7. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
  8. $output = curl_exec( $ch );
  9. curl_close($ch);
  10. echo "output:".$output;
  11. ?>


A ich API mi odpowiada:
Please specify a supported `Accept` header. Valid options: `application/json`, `application/xml`

Co może być nie tak? Dzięki za wszelkie podpowiedzi.
Michal
Go to the top of the page
+Quote Post
rad11
post 4.05.2018, 20:15:12
Post #2





Grupa: Zarejestrowani
Postów: 1 270
Pomógł: 184
Dołączył: 7.10.2012
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


Sprobuj dodac 'Content-type: application/json' jako kolejny element w tablicy z naglowkami. Pytanie tez jest takie co probujesz osiągnąć ?

Ten post edytował rad11 4.05.2018, 20:20:55
Go to the top of the page
+Quote Post
m-mike
post 4.05.2018, 20:30:58
Post #3





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 8.09.2010

Ostrzeżenie: (0%)
-----


Bez zmian, nic to nie dało.

GET /api/v1/products
Returns all possible products

Michal
Go to the top of the page
+Quote Post
Pyton_000
post 5.05.2018, 08:34:10
Post #4





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

Ostrzeżenie: (0%)
-----


Zapomniałeś jeszcze o

Kod
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
Go to the top of the page
+Quote Post
m-mike
post 5.05.2018, 08:58:20
Post #5





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 8.09.2010

Ostrzeżenie: (0%)
-----


Dzięki za wskazówkę, dodane, ale nadal zwraca to samo.


Michał
Go to the top of the page
+Quote Post
Pyton_000
post 5.05.2018, 09:56:48
Post #6





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

Ostrzeżenie: (0%)
-----


U mnie działa twój kod. Wypluwa błąd autoryzacji co jest normalne, ale cała reszta jest ok.
Go to the top of the page
+Quote Post
m-mike
post 6.05.2018, 11:25:34
Post #7





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 8.09.2010

Ostrzeżenie: (0%)
-----


Próbowałem tez przez https://apitester.com/, ale tu dzieje się dokładnie tak samo:

Response Headers
HTTP/1.1 301 Moved Permanently
Date: Sun, 06 May 2018 10:20:28 GMT
Content-Type: text/html; charset=iso-8859-1
Transfer-Encoding: chunked
Connection: keep-alive
Set-Cookie: __cfduid=dc9cc1af67e8c14d3b683380ba36e90141525602028; expires=Mon, 06-May-19 10:20:28 GMT; path=/; domain=.sendowl.com; HttpOnly
Location: https://www.sendowl.com/api/v1/products
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Server: cloudflare
CF-RAY: 416ab6e35a5d57b3-IAD

Response Body
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
<script src="/cdn-cgi/apps/head/oR54GLIzrz0H2Yq5frMVrw6eZGY.js"></script></head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="https://www.sendowl.com/api/v1/products">here</a>.</p>
</body></html>
Go to the top of the page
+Quote Post
Pyton_000
post 6.05.2018, 12:23:30
Post #8





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

Ostrzeżenie: (0%)
-----


No nie dzieje się dokładnie tak samo bo masz komunikat że masz 301.

dodaj
Kod
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
i powinno być ok
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 18.04.2024 - 02:08