Bing搜索PHP中的API(获取下一个结果)不工作

busg9geu  于 2023-11-16  发布在  PHP
关注(0)|答案(1)|浏览(139)

我有基本的代码必应搜索API,这段代码是工作,但我想得到下一个结果.这是我的代码:

$rootUri_image       = 'https://api.datamarket.azure.com/Bing/Search/v1/';
$acctKey_image       = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$query_image         = urlencode("home design ideas");
$serviceOp_image     = 'Image';
$market_image        = 'en-US';

$query_image         = urlencode("'$query_image'");
$market_image        = urlencode("'$market_image'");
$requestUri_image    = "$rootUri_image/$serviceOp_image?\$format=json&Query=$query_image&Market=$market_image";

$auth_image          = base64_encode("$acctKey_image:$acctKey_image");
$data_image          = array(  
                      'http' => array(
                      'request_fulluri' => true,
                      'ignore_errors' => true,
                      'header' => "Authorization: Basic $auth_image"
                        )
            );
$context_image   = stream_context_create($data_image);
$bing_image      = file_get_contents($requestUri_image, 0, $context_image);
$bing_image      = json_decode($bing_image);
$images          = array();
$start_image     = 0;
$end_image       = 10;

foreach($bing_image->d->results as $value)
                    {                        
                      
                        $start_image++;
                        if($start_image==$end_image)
                            {
                            break;
                            }
                        else
                            {                                   
                            $image[]    = $value->MediaUrl;
                            
                            
                            }   
                    }

echo "<pre>";
print_r($image);

字符串
我想要这样的实现代码
https://api.datamarket.azure.com/Bing/Search/v1/ImageQuery=%27home%20design%20ideas%27&Market=%27en-US%27&Adult=%27Strict%27&ImageFilters=%27Size%3Asmall%27
它尝试像这样解析和合并:

$skip                = 100;
$top                 = 10;
$query_image         = urlencode("'$query_image'");
$market_image        = urlencode("'$market_image'");
$requestUri_image    = "$rootUri_image/$serviceOp_image?\$format=json&Query=$query_image&Market=$market_image&top=$top&skip=$skip";


但我得到了错误:
注意:尝试在C:\xampp\htdocs\h\pi. php中获取非对象的属性第37行
注意:尝试在C:\xampp\htdocs\h\pi. php中获取非对象的属性第37行
Copyright © 2018 - 2019 www.jsjsj.com All Rights Reserved.粤ICP备17047777号-1
注意:未定义的变量:图像在C:\xampp\htdocs\h\pi. php行55
有人能帮帮我吗?

eufgjt7s

eufgjt7s1#

解决
我错了,在API BING URL有变量$top和$skip,这不是一个变量,所以我写

$requestUri_image    = "$rootUri_image/$serviceOp_image?\$format=json&Query=$query_image&Market=$market_image&\$skip=100&\$top=1";

字符串
它工作

相关问题