Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php embed.ly识别结果的问题有时url字段丢失_Php_Json_Api_Embed_Oembed - Fatal编程技术网

Php embed.ly识别结果的问题有时url字段丢失

Php embed.ly识别结果的问题有时url字段丢失,php,json,api,embed,oembed,Php,Json,Api,Embed,Oembed,我正在测试embed.ly,并使用一个连接的逗号分隔链接字符串来请求一个请求的多个链接的详细信息 比如: http://api.embed.ly/1/oembed?key=_key_&urls=url1,url2,url3 结果包括有关链接的一些详细信息,如描述、标题、缩略图等 有时没有url字段。在大多数情况下都有一个。这个字段包含url,据我所知,它与requeststring中的url相同 我像外键一样使用这个url字段,我需要清楚地识别结果 这是我用来从embed.ly加载js

我正在测试embed.ly,并使用一个连接的逗号分隔链接字符串来请求一个请求的多个链接的详细信息

比如:

http://api.embed.ly/1/oembed?key=_key_&urls=url1,url2,url3
结果包括有关链接的一些详细信息,如描述、标题、缩略图等

有时没有url字段。在大多数情况下都有一个。这个字段包含url,据我所知,它与requeststring中的url相同

我像外键一样使用这个url字段,我需要清楚地识别结果

这是我用来从embed.ly加载json数据的函数。我只是在一个数组上循环,该数组包含在另一个函数中提取的一些URL,并将它们内爆为查询字符串

收到json后,我检查错误,如果有错误,我将链接代码从富html恢复为基本链接标记

但是如果在发送回数据中没有使用的url,我应该如何识别数据所属的链接

private function getOPGdata(){

    $linklist = array();

    foreach ( $this->_extractions['ogp'] as &$v ) {

        $linklist[] = urlencode( $v );

    }

    $apicall = $this->_embedkey . implode( ',', $linklist );
    $data    = $this->file_get_contents_curl( $apicall );
    $data    = json_decode( $data, true );

    // we replace ogp tagged links if we don't get results
    // and reverse them to normal links
    $replace     = array();
    $replaceWith = array();

    unset( $apicall );
    unset( $linklist );
    unset( $this->_extractions['ogp'] );
    foreach ($data as &$v) {

        // check for errors
        if( isset( $v['error_code'] ) ){

            $replace[]     = '[ogp]'.$v['url'].'[ogp]';
            $replaceWith[] = '[url]'.$v['url'].'[url]';

        }

        else {

            $r = array(
                'provider_url'  => $v['provider_url'],
                'provider_name' => $v['provider_name'],
                'title'         => $v['title'],
                'description'   => $v['description'],
                'thumbnail_url' => $v['thumbnail_url'],
                'html'          => $v['html'],
                'type'          => $v['type']
            );

            $this->setOPGdata( $v['url'], $r );

        }

    }

    // finally remove links with no results
    $this->_text = str_replace( $replace, $replaceWith, $this->_text );

    return true;

}
在Embeddely.js中,他们这样做是为了跟踪结果:

  // Put everything into batches, even if these is only one.
  var batches = batch(valid_urls, options.batch), self = this;

  // Actually make those calls.
  $.each(batches, function(i, batch){
    $.ajax({
      url: self.build(method, batch, options),
      dataType: 'jsonp',
      success: function(data){
        // We zip together the urls and the data so we have the original_url
        $.each(zip([batch, data]), function(i, obj){
          var result = obj[1];
          result.original_url = obj[0];
          result.invalid = false;
          keeper.notify(result);
        });
      }
    });
  });
这在PHP中意味着什么

URL示例:

  [1]=>
  array(11) {
    ["provider_url"]=>
    string(24) "http://stackoverflow.com"
    ["description"]=>
    string(143) "I'm testing embed.ly and use a concatenated comma separated link string to request details for multiple links with one request. Something like:"
    ["title"]=>
    string(79) "embed.ly Problems to identify results beauser somtimes the url field is missing"
    ["mean_alpha"]=>
    float(191.25)
    ["thumbnail_width"]=>
    int(316)
    ["url"]=>
    string(123) "http://stackoverflow.com/questions/23095192/embed-ly-problems-to-identify-results-beauser-somtimes-the-url-field-is-missing"
    ["thumbnail_url"]=>
    string(78) "http://cdn.sstatic.net/stackoverflow/img/apple-touch-icon@2.png?v=fde65a5a78c6"
    ["version"]=>
    string(3) "1.0"
    ["provider_name"]=>
    string(13) "Stackoverflow"
    ["type"]=>
    string(4) "link"
    ["thumbnail_height"]=>
    int(316)
  }
  [2]=>
  array(11) {
    ["provider_url"]=>
    string(15) "http://embed.ly"
    ["description"]=>
    string(118) "Embedly allows developers to pull full article text for text analysis or building a read it later type applications..."
    ["title"]=>
    string(27) "Artiicle Tutorial | Embedly"
    ["mean_alpha"]=>
    float(32.7480314961)
    ["thumbnail_width"]=>
    int(399)
    ["url"]=>
    string(38) "http://embed.ly/docs/tutorials/article"
    ["thumbnail_url"]=>
    string(58) "http://embed.ly/static/images/logos/logo_color.png?v=4b245"
    ["version"]=>
    string(3) "1.0"
    ["provider_name"]=>
    string(5) "Embed"
    ["type"]=>
    string(4) "link"
    ["thumbnail_height"]=>
    int(127)
  }
}
还有一个是没有url的:

  [0]=>
  array(14) {
    ["provider_url"]=>
    string(18) "https://vimeo.com/"
    ["description"]=>
    string(316) "Writers' Block is a short film written and directed by Tom Gran and Martin Woolley and produced by WONKY Films with the support of IdeasTap. Set in a prison for criminally poor writers, it follows a gang of cons who get ahold of the script to their own lives and attempt to re-write it in order to make their escape."
    ["title"]=>
    string(14) "Writers' Block"
    ["author_name"]=>
    string(12) "WÖNKY Films"
    ["height"]=>
    int(720)
    ["thumbnail_width"]=>
    int(1280)
    ["width"]=>
    int(1280)
    ["html"]=>
    string(389) ""
    ["author_url"]=>
    string(27) "http://vimeo.com/wonkyfilms"
    ["version"]=>
    string(3) "1.0"
    ["provider_name"]=>
    string(5) "Vimeo"
    ["thumbnail_url"]=>
    string(46) "http://i.vimeocdn.com/video/468861310_1280.jpg"
    ["type"]=>
    string(5) "video"
    ["thumbnail_height"]=>
    int(720)
  }

结果总是按照它们传入的相同顺序传回。您应该能够对请求URL执行for循环,并且只需通过响应数组中的索引匹配结果。您可以执行如下操作,将请求URL映射到响应

$urls = array(
  "http://www.google.com",
  "http://www.yahoo.com"
);

$results = get_embedly_results($urls)
$resultMap = array();

for ($i = 0; $i < count($urls); ++$i) {
  resultMap[$urls[$i]] = $results[$i];
}

这是未经测试的代码,我的PHP非常生疏,但它应该能让您大致了解情况。

是的。看起来他们返回数据的顺序是正确的。但如果他们以主题url作为键返回数据,我会更高兴。谢谢关于信任。。一旦出现异常情况,由于多种原因可能会发生,这将打乱我的缓存数据库。。。因此,我所能做的就是验证数组长度,并将其与URL数进行比较,如果returnarray计数与send array计数不匹配,则跳过链接。。。我认为这是Dr.TrpOS在域中是我所能做的,域/提供者总是返回到我所能看到的,并且一旦出现一个错误,就再次跳过整个链接包。