a blog에서 게시물을 가져 오는 데 laravel-wp-api을 사용하려고합니다. Postman
을 http://idareyou.ee/blog//wp-json/wp/v2/posts
과 함께 사용하면 200 OK HTTP response
이 표시되고 Postman
은 JSON
결과를 보여줍니다. 브라우저에서Laravel Wordpress JSON REST API에서 이상한 컬 오류가 발생합니다
다음 Laravel
BlogController
getPosts()
방법 인쇄이 Curl
오류 :
{"error":{"message":"cURL error 6: Couldn't resolve host '\u003Cwp_location\u003E' (see http:\/\/curl.haxx.se\/libcurl\/c\/libcurl-errors.html)"},"results":[],"total":0,"pages":0}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use WpApi;
class BlogController extends Controller
{
public function getPosts()
{
$posts = WpApi::posts('http://idareyou.ee/blog//wp-json/wp/v2/posts');
echo json_encode($posts,true);
//return view('pages.blog', ['active'=>'navBlog'])->with('posts', $posts );
}
}
는 다른 곳에서 내 응용 프로그램에서 나는 성공적으로 다음을 사용하여 인스 타 그램 API의 일부 사진을 가져 오는하고있다. 내
BlogController
에 'fetchData'기능이 필요합니까?
function fetchData($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
$result = fetchData("https://api.instagram.com/v1/users/.......");
$result = json_decode($result, true);
$lastFive = array_slice($result['data'], 0, 5); // returns last 5 instagram pics
아무도 내가 뭘 잘못하고 있는지에 대한 조언을 줄 수 있습니까?
감사합니다. 나는 당신이 옳았다 고 생각합니다. 엔드 포인트를''endpoint '=>'http : //idareyou.ee/blog//wp-json/ '로 설정하면''404 error' {{ "error": { "message": "클라이언트 오류 : 404", "코드": 404}, "결과": [], "총": 0, "페이지": 0}' –
오른쪽 - API 호출도 조정 했습니까? 나는 당신이 상대 경로를 그냥 넘겨 준다고 생각한다 :'$ posts = WpApi :: posts ('wp/v2/posts');'(또한, 안전을 위해서 끝점에서 이중 슬래쉬를 제거했다. "wp-json": "http://idareyou.ee/blog/wp-json/") – MacPrawn
감사합니다. 지금은 끝점을''endpoint => 'http : //idareyou.ee/blog/wp-json /','$ posts = WpApi :: posts ('wp/v2/{ "오류": { "메시지": "클라이언트 오류 : 404", "코드": 404}, "결과": [], "총": 0, "페이지" : 0}' –