我正在尝试使用laravel-wp-api来获取a blog的帖子。当我使用Postman
和http://idareyou.ee/blog//wp-json/wp/v2/posts
时,我得到了200 OK HTTP response
,Postman
显示了JSON
结果。
以下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 );
}
}
在我的应用程序的其他地方,我使用以下内容从Instagram 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
任何人都可以给我任何关于我做错的提示吗?
我会检查配置文件中的这项服务 - 我猜您需要为您的呼叫设置端点(博客域)。因此,一旦你运行php artisan vendor:publish
,你应该在app / config下有一个特定的配置文件 - 看看你是否需要更改设置。
希望这可以帮助!