search

Home  >  Q&A  >  body text

Failed to obtain user information when logging in with GitHub account

When logging in to GitHub, I found that directly using curl to simulate a get request cannot obtain user information, but pasting out the link can return information when the browser directly accesses it. Please tell me how to request it in PHP

阿彬阿彬2339 days ago1250

reply all(3)I'll reply

  • 黑岩*手

    黑岩*手2018-08-30 08:40:30

    GitHub's documentation says that when calling the API, the request header needs to contain User-Agent, so directly file_get_content will produce a 403, and then the browser can access it. The solution is to use curl to simulate a get request and add User-Agent to the header of the request. You can copy the value from the browser.

    reply
    1
  • 阿彬

    Already solved, this is the method, thank you, brother

    阿彬 · 2018-09-07 17:47:34
  • ringa_lee

    ringa_lee2018-08-29 09:30:39

    Use file_get_content directly, simple and clear

    reply
    0
  • 阿彬

    file_get_content用了 但是报错403 file_get_contents(https://api.github.com/user?access_token=17a691fd9b7843166f7dc01342deac87dee0085c): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden

    阿彬 · 2018-08-29 09:41:34
  • Cancelreply