none
Did something change recently with the Bing Search API?

    Question

  • It was working until last week. Now I am getting an auth error: 

    The authorization type you provided is not supported. Only Basic and OAuth are supported

    Also, I can see that the Dataset Explorer points to https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/ whereas I am using https://api.datamarket.azure.com/Bing/Search/ as it appears in the PHP code example...

    Tuesday, October 09, 2012 8:33 PM

Answers

All replies

  • Hi,

    Nothing changed with the API. What you see in the Dataset Explorer is a full representation of the URI (for application that might be affected by protocol versioning in the future). Both URIs should work properly.

    The authorization type error is usually related to incorrect usage of Authorization header in the application.

    Did something change in your application recently?

    Thanks,

    Max

    Wednesday, October 10, 2012 7:08 AM
    Owner
  • Hi,

      >> It was working until last week. Now I am getting an auth error

    It seems the old API that requires an application ID and secret is no longer supported. Please migrate to Windows Azure Marketplace. You can refer to http://www.bing.com/webmaster/content/developers/ADM_MIGRATION_GUIDE.docx for more information.

    Best Regards,

    Ming Xu.


    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework

    Wednesday, October 10, 2012 12:11 PM
    Moderator
  • I am using PHP code straight from the ADM Migration Guide document, and again it was working until recently:

        $accountKey = '[Application_Key]';
        $ServiceRootURL =  'https://api.datamarket.azure.com/Bing/Search/';
        $WebSearchURL = $ServiceRootURL . 'Image?$format=json&Query=';
        $context = stream_context_create(array(
            'http' => array(
                'request_fulluri' => true,
                'header'  => "Authorization: Basic " . base64_encode($accountKey . ":" . $accountKey)
            )
        ));
        $request = $WebSearchURL.urlencode('\''.$_GET[search_text].'\'');
        $response = file_get_contents($request, 0, $context);



    • Edited by ne02 Sunday, October 14, 2012 8:27 PM
    Sunday, October 14, 2012 8:25 PM
  • Hi Ne02,

    For the authorization header, you shouldn't duplicate it or base64 encode it. You just need to take your take a key from https://datamarket.azure.com/account/keys and use it directly. 

    If that doesn't work, please capture the raw HTTP request (minus your key) and post it here. That will help a lot. 
    Sunday, October 14, 2012 11:38 PM
  • Thanks Nathan. I will try that... perhaps MS should update their documentation. Like I said, I took that PHP code directly from the API guidelines: http://www.bing.com/webmaster/content/developers/ADM_MIGRATION_GUIDE.docx

    And something you guys keep ignoring: this same code was working until a week a ago!

    • Edited by ne02 Sunday, October 14, 2012 11:51 PM
    Sunday, October 14, 2012 11:45 PM
  • Tried what Nathan suggested, same error: "The authorization type you provided is not supported. Only Basic and OAuth are supported"
    Sunday, October 14, 2012 11:55 PM
  • Hi ne02,

    Can you try this sample code? Please feel free to modify the query as you wish.

    Patrick

    $query = http_build_query(
      array(
       'Sources' => "'web+image+video+news+spell'",
       'Query' => "'xbox'"));
      
      $keyName='accountKey';
      $keyValue='YOUR ACCOUNT KEY';
      $accountKey = base64_encode($keyName.':'.$keyValue);

      $options = array(
      'http' =>array(
        'method' => 'GET',
        'header' => array('Authorization: Basic '.$accountKey, 'Content-type: application/atom+xml')));
      $context  = stream_context_create($options);
      $results = file_get_contents('https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/Composite?'.$query, false, $context);

    Monday, October 15, 2012 12:09 AM
  • Also, another thing to note is that your query seems not correct.

    Image?$format=json&Query="

    Needs to be

    Sources='Image'&Query='xbox'&$format=JSON

    Note the $format=JSON needs to be appended after query key value pairs not as part of key values.

    https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/Composite?Sources=%27Image%27&Query=%27xbox%27&$top=50&$format=JSON

    Monday, October 15, 2012 12:21 AM
  • Patrick, 

    I am sorry but your suggested code changes didn't help...

    See the page I created here: http://www.haydur.com/bing.php

    Here's the source code of this page:

    <html>
        <head>
            <title>PHP Bing</title>
        </head>
        <body>
            <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
                Type in a search:
                
                <input type="text" id="searchText" name="searchText"
                    value="<?php
                            if (isset($_POST['searchText']))
                            {
                                echo($_POST['searchText']); 
                            }
                            else 
                            { 
                                echo('sushi');
                            }
                           ?>"
                />
                
                <input type="submit" value="Search!" name="submit" id="searchButton" />
                <?php            
                    if (isset($_POST['submit'])) 
                    {

    // Replace this value with your account key
    $query = http_build_query(
     array(
      'Sources' => "'image'", 
      'Query' => "'xbox'"));
     
     $keyName='accountKey';
     $keyValue='iiE9irgTD---redacted---IKJohpT/pYM=';
     $accountKey = base64_encode($keyName.':'.$keyValue);

     $options = array(
     'http' =>array(
    'method' => 'GET',
    'header' => array('Authorization: Basic '.$accountKey, 'Content-type: application/atom+xml')));
     $context  = stream_context_create($options);
     $results = file_get_contents('https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/Composite?'.$query, false, $context);
    $jsonobj = json_decode($results);
                        echo('<ul ID="resultList">');
     
                        foreach($jsonobj->d->results as $value)
                        {                        
                            echo('<li class="resultlistitem"><a href="' . $value->MediaURL . '">');
                            
                            echo('<img src="' . $value->Thumbnail->MediaUrl. '"></li>');
                        }
                        
                        echo("</ul>");

    echo "<br /><br />RAW Bing output:<br /><br />".$results;
                    } 
                ?>
            </form>
        </body>
    </html>

    Monday, October 22, 2012 10:30 PM
  • Hi

    Bing search API have some issue last week, and it's been fixed on 10/23.

    If you still have the problem please follow up.

    Thanks.

    Thursday, October 25, 2012 2:07 AM
    Moderator
  • As of January 5th 2014 I have the very same problem (using the sample C# source code from the documentation). Any idea what's going on?

    My code:

    var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri));
    
    // Configure bingContainer to use your credentials. 
    bingContainer.Credentials = new NetworkCredential(accountKey, accountKey);
                    
    // Build the query. 
    var imageQuery = bingContainer.Image(searchQuery, null, null, null, null, null, null);
    
    imageQuery.BeginExecute(_onImageQueryComplete, imageQuery);
    

    The results in the following error:

    "The authorization type you provided is not supported. Only Basic and OAuth are supported"

    with this stacktrace:

       at System.Data.Services.Client.QueryResult.EndExecuteQuery[TElement](Object source, String method, IAsyncResult asyncResult)
       at System.Data.Services.Client.DataServiceRequest.EndExecute[TElement](Object source, DataServiceContext context, String method, IAsyncResult asyncResult)
       at System.Data.Services.Client.DataServiceQuery`1.EndExecute(IAsyncResult asyncResult)
       at StackOverflow.Samples.BingSearch.Finder._onImageQueryComplete(IAsyncResult imageResults)
       at System.Data.Services.Client.BaseAsyncResult.HandleCompleted()
       at System.Data.Services.Client.QueryResult.HandleCompleted(PerRequest pereq)
       at System.Data.Services.Client.QueryResult.AsyncEndRead(IAsyncResult asyncResult)
       at System.Data.Services.Client.BaseAsyncResult.<>c__DisplayClass2.<GetDataServiceAsyncCallback>b__1(IAsyncResult asyncResult)
       at System.IO.Stream.ReadWriteTask.InvokeAsyncCallback(Object completedTask)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.IO.Stream.ReadWriteTask.System.Threading.Tasks.ITaskCompletionAction.Invoke(Task completingTask)
       at System.Threading.Tasks.Task.FinishContinuations()
       at System.Threading.Tasks.Task.FinishStageThree()
       at System.Threading.Tasks.Task.FinishStageTwo()
       at System.Threading.Tasks.Task.Finish(Boolean bUserDelegateExecuted)
       at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
       at System.Threading.Tasks.Task.ExecuteEntry(Boolean bPreventDoubleExecution)
       at System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
       at System.Threading.ThreadPoolWorkQueue.Dispatch()
       at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

    (((System.Data.Services.Client.DataServiceQueryException)$exception).InnerException).StackTrace

       at System.Data.Services.Client.BaseAsyncResult.EndExecute[T](Object source, String method, IAsyncResult asyncResult)
       at System.Data.Services.Client.QueryResult.EndExecuteQuery[TElement](Object source, String method, IAsyncResult asyncResult)

    I tried new NetworkCredentials("accountKey", accountKey) and new NetworkCredentials("", accountKey) without success.

    Any ideas?

    Sunday, January 05, 2014 1:57 PM
  • Did you actually assign your account key? In addition, please validate you are subscribed to correct Bing offering.

    thanks,

    Max

    Tuesday, January 07, 2014 8:37 AM
    Owner
  • Thanks for your help, Max.


    On datamarket.azure.com/account/datasets it shows that I subscribed to the Bing Search API:

     
    Bing Search API

    Microsoft

    (Started on 05.01.2014)
     
    Subscription

    5,000 Transactions/month
     
    Active

    4,998 Transactions remaining


    I'm not sure what you meant with "assigning my account key". I have added a new account key and tried both my default account key and a new created one. Both lead to the same error. Not sure if it's important but I'm running on a Windows Phone 8 device and develop in VS Studio 2012.


    Thanks in advance,

    yours

    Robert

    Tuesday, January 07, 2014 10:41 AM