MicrosoftDocs / azure-docs

Open source documentation of Microsoft Azure
https://docs.microsoft.com/azure
Creative Commons Attribution 4.0 International
10.25k stars 21.42k forks source link

Adding websearch API quickstart for golang #5312

Closed Nhoya closed 6 years ago

Nhoya commented 6 years ago

Hi, Since i wrote a library for Bing Websearch in golang i was wondering if I can contribute adding a quickstart example on the doc (since it's missing for golang).

If for you is ok please let me know if you prefer a pure go version, the library implementation or both

MohitGargMSFT commented 6 years ago

Thanks for your offer to collaborate! I have assigned it to the document author team representative to help with an update.

swhite-msft commented 6 years ago

@MicrosoftDocs/azure-cxp-triage please reassign to @MikeDodaro.

MikeDodaro commented 6 years ago

@Nhoya Thanks, I think we can add client code examples to the documentation in the Go language. Our samples are segregated by endpoints and languages. See the documents under Search: https://docs.microsoft.com/en-us/azure/#pivot=products&panel=ai There are code samples for the REST APIs in several languages for each of the search endpoints: News; Video; Web; Entity; Image. You could add an example using your library and include dependencies, something like the Quickstarts for each case. This is just my opinion, and there is some discussion about it here. The managers may want you to write complete code in the quickstart example.

Nhoya commented 6 years ago

For me is totally the same, and i'm open to all the possibility, i wrote the library because i had to include the bing search on one of my projects but since i thought it could be useful to other people I converted it in to a library easy to use (at the moment for a simple search you just need literally 2 function calls)

MikeDodaro commented 6 years ago

After some discussion here, it seems like the easiest way to get this approved is if you write the whole example in a quickstart without dependency to an external library. That way users see the full code requirements in one place.

Nhoya commented 6 years ago

Sure, no problem, i'll drop a PR

MikeDodaro commented 6 years ago

There will eventually be an example for each of the endpoints News; Video; Web; Entity; Image.

Nhoya commented 6 years ago

I have a problem obtaining acces to the private repo, following the link here says i'm not authorized to open the link

MikeDodaro commented 6 years ago

@Nhoya I have sent a query to support to get info about how you can enlist. Sorry for the delay. While you are waiting, can you write instructions for how to setup and run your samples?

MikeDodaro commented 6 years ago

@Nhoya Try this page for external contributors: https://docs.microsoft.com/contribute/contribute/get-started-setup-github

Nhoya commented 6 years ago

sure, you have to install and configure go then create a file something.go, paste the complete example inside and insert a valid API Key in the token variable

package main

import (
        "fmt"
        "io/ioutil"
        "net/http"
)

func main() {
        const endpoint = "https://api.cognitive.microsoft.com/bing/v7.0/search"
        token := "123457890123456890"
        searchTerm := "Microsoft Cognitive Services"

        req, err := http.NewRequest("GET", endpoint, nil)
        if err != nil {
                panic(err)
        }

        client := new(http.Client)
        param := req.URL.Query()
        param.Add("q", searchTerm)
        req.URL.RawQuery = param.Encode()
        req.Header.Add("Ocp-Apim-Subscription-Key", token)
        resp, err := client.Do(req)
        if err != nil {
                panic(err)
        }
        defer resp.Body.Close()
        body, err := ioutil.ReadAll(resp.Body)
        if err != nil {
                panic(err)
        }
        fmt.Println(string(body))
}

Then just go run yourfile.go

Note: The example doesn't handle the JSON parsing, if you need it just let me know

Nhoya commented 6 years ago

@MikeDodaro I already setupped my git env, the problem is that I need an authorization for a private repository, following the link to get it (i guess?) in the readme it says forbidden (if you check my PR it was closed by the PR bot saying that PR must be sent to a private repo)

MikeDodaro commented 6 years ago

Ok, we are working on it. Support is responding. I'll let you know as soon as possible.

MikeDodaro commented 6 years ago

@Nhoya Try this: where the metadata says: ms.author: Nhoya , change to ms.author: rosh

Nhoya commented 6 years ago

Still failing

MikeDodaro commented 6 years ago

I noticed this: ms.date: 09/03/2018 . That is not US style and it would mean September 9, 2018. Try changing to 03/09/2018

Nhoya commented 6 years ago

Still failing, i don't think is related to the source of the markdown page

MikeDodaro commented 6 years ago

We are trying to find a bot expert to see what needs to be done to get this accepted.

MikeDodaro commented 6 years ago

Please don't change anything while we investigate.

MikeDodaro commented 6 years ago

I have pulled your branch into mine. We'll need an email address for you, per this: ms.author: The email alias of the FTE sponsor, and the full email address of the community author.

Nhoya commented 6 years ago

Since my address is public i'v no problem in sending it here nhoyadx [at] gmail [dot] com

MikeDodaro commented 6 years ago

Can you see this? https://github.com/MicrosoftDocs/azure-docs-pr/pull/35014

Nhoya commented 6 years ago

No i can't since the -pr repository is private and I need an invite to join

MikeDodaro commented 6 years ago

We won't be able to get it through editorial review before 3:00 PM, but it will probably get published on Monday. I may have a few more questions.

Nhoya commented 6 years ago

Sure, totally not a problem for me, if you have any questions feel free to ask

AdamS-MSFT commented 6 years ago

@Nhoya Looks like the modification was merged.