Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [Curl] League of Legends API, Problem z pobraniem danych
Deusald
post 21.06.2014, 00:13:45
Post #1





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 20.06.2014

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


Witam wink.gif
Mam pewien problem z implementacją API League of Legends przez Curl. Mam nadzieję, że mi pomożecie bo siedzę nad tym już 3 dni i nic nie mogę wykombinować. W php już trochę robiłem. Wykonałem nawet od 0 forum wink.gif Na stronie:
https://www.mashape.com/timtastic/league-of...3;documentation
Znajduje się API do popularnej gry League of Legends. Chciałbym je wykorzystać na mojej stronie używając PHP(Curl).
Aby uzyskać dostęp mam taki oto kod:
  1. curl --include --request GET 'https://community-league-of-legends.p.mashape.com/api/v1.0/EUNE/summoner/getSummonerBySummonerId/27896998' \
  2. --header "X-Mashape-Authorization: d8Z8W5wSl7iMIOPkrP1OHorhpRAy3ObH"

Klucz jest testowy więc mogę go na chwilę udostępnić. Jeśli wkleić by sam adres do przeglądarki to otrzymamy:
  1. {"message":"Invalid Mashape key. If you are a Mashape user, get your key from your dashboard at <a href="https://www.mashape.com/login" target="_blank">https://www.mashape.com/login</a> -
  2. To create a free Mashape account instead, go to <a href="https://www.mashape.com/signup&quot;}" target="_blank">https://www.mashape.com/signup"}</a>

Tylko nie wiem jak umieścić ten klucz w linku. Próbowałem coś kombinować z tym:
http://www.jonasjohn.de/snippets/php/curl-example.htm
Ale nie wychodziło. Wynik linku powyżej z kluczem powinien być taki:
  1. {
  2. "array": [
  3. "Deusald"
  4. ]
  5. }

Bardzo Was proszę o pomoc bo nie mam już pomysłu.
Go to the top of the page
+Quote Post
johny_s
post 21.06.2014, 01:06:48
Post #2





Grupa: Zarejestrowani
Postów: 594
Pomógł: 122
Dołączył: 17.07.2005
Skąd: P-na

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


Klucz umieszczasz w nagłówkach nie w linku
Go to the top of the page
+Quote Post
Deusald
post 21.06.2014, 01:20:34
Post #3





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 20.06.2014

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


Jak go umieścić w tym nagłówku?
Go to the top of the page
+Quote Post
johny_s
post 21.06.2014, 01:31:16
Post #4





Grupa: Zarejestrowani
Postów: 594
Pomógł: 122
Dołączył: 17.07.2005
Skąd: P-na

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


Cytat(Deusald @ 21.06.2014, 01:20:34 ) *
Jak go umieścić w tym nagłówku?

http://stackoverflow.com/questions/8115683...-custom-headers
pierwszy link z google...
Go to the top of the page
+Quote Post
Deusald
post 21.06.2014, 01:39:06
Post #5





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 20.06.2014

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


  1. <?php
  2.  
  3. $PageUrl = 'https://community-league-of-legends.p.mashape.com/api/v1.0/EUNE/summoner/getAggregatedStats/27896998';
  4. $curl = curl_init( $PageURL );
  5. curl_setopt( $curl, CURLOPT_HTTPHEADER,array('X-Mashape-Authorization: d8Z8W5wSl7iMIOPkrP1OHorhpRAy3ObH'));
  6. $result = curl_exec( $curl );
  7. curl_close( $curl );
  8.  
  9. echo $result;
  10. ?>

Na tym momencie skończyłem poszukiwania rozwiązania i napisałem tutaj. Zrobiłem to co napisałeś. Zmienna pomimo tego jest pusta.
Go to the top of the page
+Quote Post
johny_s
post 21.06.2014, 01:55:27
Post #6





Grupa: Zarejestrowani
Postów: 594
Pomógł: 122
Dołączył: 17.07.2005
Skąd: P-na

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


To jeszcze wypadało by wiedzieć co zwraca funkcja której się używa

http://www.php.net/manual/en/function.curl-exec.php

ustaw CURLOPT_RETURNTRANSFER

Ten post edytował johny_s 21.06.2014, 01:55:51
Go to the top of the page
+Quote Post
Deusald
post 21.06.2014, 14:32:23
Post #7





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 20.06.2014

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


W ten sposób?
  1. <?php
  2.  
  3. $PageUrl = 'https://community-league-of-legends.p.mashape.com/api/v1.0/EUNE/summoner/getAggregatedStats/27896998';
  4. $curl = curl_init( $PageURL );
  5. curl_setopt( $curl, CURLOPT_HTTPHEADER,array('X-Mashape-Authorization: d8Z8W5wSl7iMIOPkrP1OHorhpRAy3ObH'));
  6. curl_setopt( $curl, CURLOPT_RETURNTRANSFER);
  7. $result = curl_exec( $curl );
  8. curl_close( $curl );
  9.  
  10. echo $result;
  11. ?>

Nadal zmienna jest pusta.

EDIT:
Zrobiłem też tak, ale również zmienna jest pusta.
  1. $curl = curl_init();
  2.  
  3. curl_setopt_array($curl, array(
  4. CURLOPT_RETURNTRANSFER => 1,
  5. CURLOPT_URL => 'https://community-league-of-legends.p.mashape.com/api/v1.0/EUNE/summoner/getAggregatedStats/27896998',
  6. CURLOPT_HTTPHEADER => array('X-Mashape-Authorization: d8Z8W5wSl7iMIOPkrP1OHorhpRAy3ObH')
  7. ));
  8. $resp = curl_exec($curl);
  9. curl_close($curl);
  10.  
  11. echo $resp;


Ten post edytował Deusald 21.06.2014, 14:43:07
Go to the top of the page
+Quote Post
johny_s
post 21.06.2014, 15:03:49
Post #8





Grupa: Zarejestrowani
Postów: 594
Pomógł: 122
Dołączył: 17.07.2005
Skąd: P-na

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


ja dostaje cos takiego z tego Twojego zapytania:

Kod
johny@dellbi:~/test$ php test.php
{
        "key": {
                "season": 4,
                "userId": 27896998,
                "gameMode": "CLASSIC",
                "gameModeString": "CLASSIC",
                "dataVersion": 0
        },
        "lifetimeStatistics": {
                "array": []
        },
        "dataVersion": 0
}
Go to the top of the page
+Quote Post
Deusald
post 21.06.2014, 15:38:36
Post #9





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 20.06.2014

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


Dobra działa smile.gif Cba.pl ma wyłączone Curl a w xammpie zapomniałem włączyć haha.gif Wielkie dzięki za pomoc johny_s smile.gif
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: 29.04.2025 - 09:55