Azure Marketplace Authentication Bing Search Authentication API in Java

How can I authenticate in Java to use the new bing search query from Azure Marketplace? Migration Guide Doesn't Provide You with Java Information

+5
source share
1 answer

You will need to encode your KeyKey account on Base64 and transfer it to each request using the Authorization header.

String bingUrl = "https://api.datamarket.azure.com/Bing/Search/................";

String accountKey = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
byte[] accountKeyBytes = Base64.encodeBase64((accountKey + ":" + accountKey).getBytes());
String accountKeyEnc = new String(accountKeyBytes);

URL url = new URL(bingUrl);
URLConnection urlConnection = url.openConnection();
urlConnection.setRequestProperty("Authorization", "Basic " + accountKeyEnc);

...

This code is based on a PHP example found in Migrating to the Bing Search API in a Windows Azure Marketplace document .

Refresh . The call to encodeBase64 has been changed, it should be as follows: accountKey + ":" + accountKey

+8
source

All Articles