我是Laravel的新东西和API的新手(以前从未这样做过),但我知道PHP和Javascript。但我想尽快学习这些东西,很抱歉,如果我的问题很愚蠢:D
所以我想问你们的是:
因为有人说您无法向Laravel添加外部API。
POST /api/oauth/token HTTP/1.1 Host: api.######.#### Authorization: Basic /* some unique strings and numbers here */ Content-Type: application/x-www-form-urlencoded grant_type=client_credentials
对不起我的英语,但我已经尽力解释我想要的内容。 谢谢:))
答案 0 :(得分:2)
不知道这些“有些人”,但你可以用Laravel做任何你想做的事情,它没有任何限制。只要PHP可以做到,Laravel就可以做到。
搜索实现API的包,例如
composer require <api-package>
例如要在PHP中使用Instagram API,可以试试这个包:
composer require cosenary/instagram
所有依赖项都在composer.json
中监听。
如果找不到,使用php-curl
可以轻松实现HTTP API包。 (curl
中命令行中的PHP
)。阅读相应的API文档,并逐一实现API的每个资源路由。
可以找到curl
的完整PHP
文档here。
答案 1 :(得分:2)
使用guzzle,并对以下示例的任何网络服务执行您的请求:
$response = $client->request('POST', 'http://example.com/api/oauth/token', [
'headers' = [
'Authorization' => 'Basic your_token'
],
'form_params' => [
'grant_type' => 'client_credentials',
]
]
]);