【问题标题】:Include URI to resource in API response在 API 响应中包含资源的 URI
【发布时间】:2014-12-12 13:11:33
【问题描述】:

我正在努力将Richardsons Maturity Model 中现有的 API(Instagram) 提高到第 3 级。

基本上,我想在 API 响应中包含资源的 uri。

这是一个例子。这是用户资源的 JSON 表示。

{
    "username": "emil",
    "bio": "",
    "website": "",
    "profile_picture": "https://instagramimages-a.akamaihd.net/profiles/anonymousUser.jpg",
    "full_name": "Yes",
    "id": "1279132381" 
}

如您所见,我们得到了这个用户的 id。然后我希望能够在 JSON 中包含该资源的 uri,就像这样。

{
    "username": "emil",
    "bio": "",
    "website": "",
    "profile_picture": "https://instagramimages-a.akamaihd.net/profiles/anonymousUser.jpg",
    "full_name": "Yes",
    "id": "1279132381",
    "uri": "users/1279132381"
}

这里我们有一个包含在响应中的用户资源的 URI,这是我希望能够做到的。

我真的不知道从哪里开始。我可以成功利用 Instagram API 并获取原始数据,但我不知道下一步该做什么。

非常感谢有关如何完成此任务的建议。我认为可能有某种库可以简化这一点,但我还没有找到任何东西。

我正在使用 Laravel 框架在 PHP 中进行开发。

谢谢!

【问题讨论】:

  • 你可以看看这个帖子link

标签: php json instagram-api


【解决方案1】:

你的例子:

$arr = array(
    'username' => "emil",
    'bio' => "",
    'website' => "",
    'profile_picture' => "https://instagramimages-a.akamaihd.net/profiles/anonymousUser.jpg",
    'full_name' => "Yes",
    'id' => "1279132381"
    );

$arr['uri'] = 'users/1279132381';

echo json_encode($arr);

【讨论】:

    猜你喜欢
    • 2019-10-20
    • 1970-01-01
    • 1970-01-01
    • 2011-12-10
    • 2016-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多