2016-04-03 60 views
0

我对这个Laravel的东西和API也是新的(以前从未这样做过),但是我知道PHP和Javascript。但我想尽快学会这些东西,很抱歉,如果我的问题是愚蠢的:d将外部API添加到Laravel 5.2

所以我要问你们是什么:

  1. 那是可能的外部API添加到Laravel 5.2?我需要把它放在哪里?

因为有人说你不能添加外部API给Laravel。

  1. 如何将此API应用于Laravel(如果可能的话)?
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 

对不起,我的英语,但我已经试图解释什么,我想清楚越好。 谢谢:)

回答

2

不知道这些“有些人”,但你可以做任何你想要的东西与Laravel,它没有任何限制。只要PHP能做到,Laravel就可以做到。

要么搜索实现API的包,例如

composer require <api-package> 

e.g要使用Instagram的API在PHP中,可能会试试这个包:

composer require cosenary/instagram 

所有相关性收听composer.json

如果找不到它,可以使用php-curl轻松实现HTTP API包。 (来自PHP命令行的curl)。阅读相应的API文档,并继续逐个实现API的每个资源路由。

PHP的完整curl文档可以在here找到。

+0

您好,感谢您的回答我真的很感激! [链接](https://github.com/php-curl-class/php-curl-class) 对于这个php-curl我可以使用该回购? –

+0

@KhrisnaGunanasurya我已通过官方文档链接更新了答案。它将包括安装。如果满足您的需求,您可以标记答案并向上投票。 – activatedgeek

2

使用狂饮,而这样的例子在下面的任何Web服务执行您的要求:

$response = $client->request('POST', 'http://example.com/api/oauth/token', [ 
     'headers' = [ 
      'Authorization' => 'Basic your_token' 
     ], 
     'form_params' => [ 
      'grant_type' => 'client_credentials', 
      ] 
     ] 
    ]); 

这里指http://guzzle.readthedocs.org/en/latest/overview.html