dsideal2015 2017-02-17 17:45
浏览 100
已采纳

尝试检索个人资料信息时,linkedin登录返回404

I have an app on linkedin that uses the login api. It is a web app that makes use of go and the goth authentication library. Up until a few days ago my app was authenticating users fine. Now it returns this error message:

linkedin responded with a 404 trying to fetch user information

The app has been running continuously without updates for weeks. So there hasn't been any code changes.

I should mention that it does bring me to the login page but after entering my username and password it redirects and outputs the aforementioned error

The goth oauth api code is located here: https://github.com/markbates/goth/blob/master/providers/linkedin/linkedin.go

It essentially calls this url with the access token http://api.linkedin.com/v1/people/~:(id,first-name,last-name,headline,location:(name),picture-url,email-address)

Does anyone know if the api endpoints have changed or any other reason authentication would just stop working?

I've been checking the blog but I see no updates in regards to the api and there doesn't seem to be a way to reach linkedin developer support as it just points to stackoverflow.

  • 写回答

2条回答 默认 最新

  • doudunyi3796 2017-02-18 20:35
    关注

    So after digging deeper into this issue. It seems that linkedin is now returning http 2.0 responses from their api.

    I discovered this by writing a small go program which I ran on my local machine and on the aws instance where the server code is located.

    package main
    
    import (
        "fmt"
        "io/ioutil"
        "net/http"
        "net/http/httputil"
        "net/url"
    )
    
    const (
        bearerToken string = "AQVJampuUSuvWs5beuCvHiJYC--"
    )
    
    func main() {
    
        userEndpoint := "//api.linkedin.com/v1/people/~:(id,first-  name,last-name,headline,location:(name),picture-url,email-address)?format=json"
    
    client := &http.Client{}
    
    req, err := http.NewRequest("GET", "", nil)
    
    req.URL = &url.URL{
        Scheme: "https",
        Host:   "api.linkedin.com",
        Opaque: userEndpoint,
    }
    
    req.Header.Set("Authorization", "Bearer "+bearerToken)
    resp, err := client.Do(req)
    
    request, _ := httputil.DumpRequest(req, true)
    
    fmt.Println("request:", string(request))
    
    data, _ := ioutil.ReadAll(resp.Body)
    
    response, _ := httputil.DumpResponse(resp, false)
    
    resp.Body.Close()
    
    fmt.Println("response:", string(response))
    
    fmt.Println(err, req.URL.String(), string(data))
    }
    

    When running this on my local machine the api returned a response with the profile data. When I ran it on the aws instance it returned a 404 with an http 2.0 header

    Here is an excerpt of the output of running this program on aws

    request: GET https://api.linkedin.com/v1/people/~?format=json HTTP/1.1 Host: api.linkedin.com Authorization: Bearer AQVJampuUSuvWs5beu--

    response: HTTP/2.0 404 Not Found Content-Length: 5530 Cache-Control: no-store Content-Language: en Content-Type: text/html Date: Sat, 18 Feb 2017 03:45:21 GMT X-Li-Pop: prod-lva1-h2

    <!-- EF of static content included-->
    <html>
      <head>
      <title>404: Not Found</title>
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <style type="text/css">
     /* GLOBAL */
    

    Now I don't know if this a bug or expected behaviour but it appears that linkedin is returning http 2.0 responses when go is picking up causing the 404.

    They way I was able to fix it was to turn off http 2.0 client support in go itself. By setting the following environment variable

    GODEBUG=http2client=0

    At which point the linkedin api returns the profile information.

    I'm curious to know if this is a bug with linkedin or go. Hopefully someone from linkedin can chime in.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 matlab实现基于主成分变换的图像融合。
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊