【问题标题】:How to use JSON oEmbed specifications in PHP?如何在 PHP 中使用 JSON oEmbed 规范?
【发布时间】:2013-12-19 01:26:51
【问题描述】:

我正在尝试使用 OAuth 2.0、PHP 和 cURL 将照片发布到微博服务 Alpha.App.net,我需要为此使用 JSON oEmbed 规范

以下是我尝试过的,但它会导致错误响应:

“错误请求:'annotations': 必须是一个列表”

function sendMessage()
{
$postData = array(
 'text' => "test",
'annotations' => array('type' => 'net.app.core.oembed',
  'version' => '1.0',
        'type' => 'photo',
        'width' => 240,
        'height' => 160,
        'title' => 'ZB8T0193',
        'url' => 'http://farm4.static.flickr.com/3123/2341623661_7c99f48bbf_m.jpg',
        'author_name' => 'Bees',
        'author_url' => 'http://www.flickr.com/photos/bees/',
        'provider_name' => 'Flickr',
        'provider_url' => 'http://www.flickr.com/',
        'embeddable_url' => 'http://www.flickr.com/photos/bees/2341623661/')
);


$ch = curl_init('https://alpha-api.app.net/stream/0/posts');
curl_setopt_array($ch, array(
    CURLOPT_POST => TRUE,
    CURLOPT_RETURNTRANSFER => TRUE,
    CURLOPT_HTTPHEADER => array('Authorization: Bearer '.'0123456789',      
'Content-Type: application/json'
    ),
    CURLOPT_POSTFIELDS => json_encode($postData)
));

这是来自docs 的原始 JSON:

{
    "type": "net.app.core.oembed",
    "value": {
        "version": "1.0",
        "type": "photo",
        "width": 240,
        "height": 160,
        "title": "ZB8T0193",
        "url": "http://farm4.static.flickr.com/3123/2341623661_7c99f48bbf_m.jpg",
        "author_name": "Bees",
        "author_url": "http://www.flickr.com/photos/bees/",
        "provider_name": "Flickr",
        "provider_url": "http://www.flickr.com/",
        "embeddable_url": "http://www.flickr.com/photos/bees/2341623661/"
    }
}

我需要更改哪些内容才能使其成为列表?

【问题讨论】:

    标签: php json curl oauth-2.0


    【解决方案1】:

    将您的注释打包到另一个数组中,例如 'annotations' => array(array(...)) 示例如下:

    $postData = array(
     'text' => "test",
    'annotations' => array(array('type' => 'net.app.core.oembed',
      'version' => '1.0',
            'type' => 'photo',
            'width' => 240,
            'height' => 160,
            'title' => 'ZB8T0193',
            'url' => 'http://farm4.static.flickr.com/3123/2341623661_7c99f48bbf_m.jpg',
            'author_name' => 'Bees',
            'author_url' => 'http://www.flickr.com/photos/bees/',
            'provider_name' => 'Flickr',
            'provider_url' => 'http://www.flickr.com/',
            'embeddable_url' => 'http://www.flickr.com/photos/bees/2341623661/'))
    );
    

    然后再次发送请求。我猜他们同时接受多张图片提交。

    【讨论】:

    • 谢谢!你知道如何使用 PHP 将图像上传到 app.net 吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 2011-05-09
    • 1970-01-01
    • 2011-01-08
    • 1970-01-01
    • 2022-06-22
    • 2019-11-18
    相关资源
    最近更新 更多