Bing API from Windows Phone 8 App


  • I have an existing app that has been working for a very long time on Windows Phone 7.  I just got a new Windows Phone 8 device and decided to spend some time upgrading my apps to support the new OS as well.

    After getting everything working I am running into a problem with Bing Search. This is the same code, just upgraded to WP8 using VS 2012.

    After the callback when I get the results:

    varnewsQuery = (DataServiceQuery<Bing.NewsResult>) ar.AsyncState;

    varresults = newsQuery.EndExecute(ar);

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

    I am using the latest BingContainer from the data market site. With these params:

    varbingContainer = newBing.BingSearchContainer(newUri(""));

    bingContainer.Credentials =

    newNetworkCredential(NFLConfig.BingAPIAccountKey, NFLConfig.BingAPIAccountKey);

    I have seen some people say that you should only use the account key for the password, but this code works today in WP7.

    What am I missing?

    Jason Short

    Thursday, November 22, 2012 12:57 AM


All replies

  • Hi, please try to use the REST API directly. For example:

     WebClient webClient = new WebClient();
                webClient.Credentials = new NetworkCredential("key", "key");
                webClient.DownloadStringCompleted += webClient_DownloadStringCompleted;
                webClient.DownloadStringAsync(new Uri($top=50&$format=Atom));

    It's working fine for me on WP8 emulator. Please also make sure the key is correct.

    Best Regards

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

    Thursday, November 22, 2012 9:34 AM
    1. For WP8 you have to go on NuGet  within VS 2012 and search for Microsoft.Data.Services.Client.WindowsPhone and download the OData Client for Windows Phone Apps first.
    2. When using this with WP8, you have to turn off UseDefaultCredentials (ex bingContainer.UseDefaultCredentials = false). This is the one notable change between WP7 and WP8 that I've realized. After you do this, your queries will work.
    Monday, November 26, 2012 9:57 PM
  • I had expected the default to be turned off when I assigned a credential to it.  Making this change right before setting the credential worked.  Thanks.

    Jason Short

    Thursday, November 29, 2012 7:53 PM