Forum Discussion
Google Image API - how to handle returned data?
- 7 years ago
You can't. At least according to this Stack Overflow answer. The response the Google API returns is in Binary format, which doesn't support image files.
It's interesting however, that when I navigate my browser to a Google Places API endpoint, it redirects me to a googleusercontent url tht contains images. I can use this URL of course to show the images. But I don't know how to capture the redirect URL programmatically through Power BI.
You can't. At least according to this Stack Overflow answer. The response the Google API returns is in Binary format, which doesn't support image files.
It's interesting however, that when I navigate my browser to a Google Places API endpoint, it redirects me to a googleusercontent url tht contains images. I can use this URL of course to show the images. But I don't know how to capture the redirect URL programmatically through Power BI.
Hi,
Thanks for the input and that is a shame. I am completely news to APIs and was pleased to be able to call the Places API without too much trouble!
I've looked into getting a Bing / Azure API Key and try to call the Bing Image Search API v7 instead, but I can't seem to find the equivalent Web call, eg the same format as the Google call I used previously (HTML?). Something like this:
https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input= Tower%20Of%20London&inputtype=textquery&fields=photos,formatted_address,name,opening_hours,rating&key=xxxxxxxxxxxxxxxxxxxxxxxxx
The Bing documentation has code to build an API in: C#, Java, Node.js, PHP, Python, Ruby.
How can go I about finding the Web call which Power BI would accept?
Thanks
Mark
- tonmcg7 years agoResolver II
The Bing Image Search API v7 seems to have what you're looking for. To use it, you'll need an Azure Cognitive Services account, which you can learn how to do here.
I quickly put together a Power Query M code sample that searches the Bing Image Search API for "Tower of London":
let API_KEY = <place your Bing Image Search API key here>, q = "Tower of London", domain = "https://api.cognitive.microsoft.com", path = "/bing/v7.0/images/search", endpoint = Uri.Combine(domain, path), request = Web.Contents( endpoint, [ Query = [ q = q ], Headers = [ #"Ocp-Apim-Subscription-Key" = API_KEY ] ] ), response = Json.Document(request), value = response[value], tableOfValues = Table.FromList(value, Splitter.SplitByNothing(), {"values"}, null, ExtraValues.Error), ExpandedValues = Table.ExpandRecordColumn(tableOfValues, "values", Record.FieldNames(tableOfValues{0}[values])), DefinedDataTypes = Table.TransformColumnTypes(ExpandedValues,{{"webSearchUrl", type text}, {"name", type text}, {"thumbnailUrl", type text}, {"datePublished", type datetime}, {"isFamilyFriendly", type logical}, {"creativeCommons", type text}, {"contentUrl", type text}, {"hostPageUrl", type text}, {"contentSize", type text}, {"encodingFormat", type text}, {"hostPageDisplayUrl", type text}, {"width", Int64.Type}, {"height", Int64.Type}, {"hostPageFavIconUrl", type text}, {"thumbnail", type any}, {"imageInsightsToken", type text}, {"insightsMetadata", type any}, {"imageId", type text}, {"accentColor", type text}}) in DefinedDataTypesIt gives me this result:
Note: I used the Chiclet Slicer to show these images in Power BI.
- MarkSL7 years agoHelper V
Wow tonmcg - I really appreciate your help with that!
I've been able to get an Azure Key, create a custom function with a parameter using your script and it works well when using our 'Tower Of London' example. However if I call it with something more obscure, then I get an error.
For example using a search of "vw golf gti" returns the error:
Expression.Error: The column 'creativeCommons' of the table wasn't found. Details: creativeCommons
Any thoughts?
- tonmcg7 years agoResolver II
It sounds like results from the Bing Image Search API don't all have the same columns. Delete the last DefinedDataTypes step. It tries to define a data type for the creativeCommons column, which doesn't exist in these results.