【问题标题】:I have established the connection to LinkedIn using REST API call. But I am facing the issue while fetching the related connections我已经使用 REST API 调用建立了与 LinkedIn 的连接。但是我在获取相关连接时遇到了这个问题
【发布时间】:2020-10-06 14:50:33
【问题描述】:

我已经使用 REST API 调用在 Salesforce 和 LinkedIn 之间建立了连接。但是我在将相关连接和网络数据提取到销售人员时遇到了这个问题。

据我所知,我的 Endpoint URL 遇到了问题,请您帮我解决这个问题。

public void doFetchBasicInfo(){

    String errorMessage ='';
    Http http = new Http();
    HttpRequest httpReq = new HttpRequest();
    HttpResponse httpRes = new HttpResponse();
    
    List<LinkedIn_Information__c> linkedlnInfoListNew = [Select Id, Name,Access_Token__c,Expires_In_Seconds__c From LinkedIn_Information__c Where Name='LinkedlnInfo'];
    system.debug('linkedlnInfoListNew'+linkedlnInfoListNew);
    httpReq.SetMethod('GET');
  httpReq.setEndpoint('https://api.linkedin.com/v2/me?projection=(id,firstName,lastName)');    
    
    //httpReq.setEndpoint('https://api.linkedin.com/v2/people/~/connections');
    httpReq.setHeader('Authorization', 'Bearer '+linkedlnInfoListNew[0].Access_Token__c);
    httpReq.setHeader('Content-Type', 'application/json');
             
    try{
        httpRes = http.send(httpReq);
        system.debug('httpRes'+httpRes.getBody());
        if(httpRes.getStatusCode() == 200){
            Map<String,object> TokenInfo = (Map<String,object>)JSON.deserializeUntyped(httpRes.getBody());
            String firstName = String.valueOf(TokenInfo.get('firstName'));
            String lastName = String.valueOf(TokenInfo.get('lastName'));
            String headline = String.valueOf(TokenInfo.get('headline'));
            
            BasicInfo = firstName +'  ' + lastName +'  '+headline;
            
        }else{
            errorMessage = 'Unexpected Error while communicating with LinkedIn API. '
                                +'Status '+httpRes.getStatus()+' and Status Code '+httpRes.getStatuscode();
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, errorMessage));
        }
    }catch(System.Exception e){
        System.debug('#### Exception Excuted '+e.getStackTraceString()+'  '+e.getMessage());
        if(String.valueOf(e.getMessage()).startsWith('Unauthorized endpoint')){
            errorMessage =  'Unauthorize endpoint: An Administer must go to Setup -> Administer -> Security Control ->'
                                +' Remote Site Setting and add '+' '+ 'https://api.linkedin.com/ '+' Endpoint';
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, errorMessage));
        }else{
            errorMessage = 'Unexpected Error while communicating with LinkedIn API. '
                                +'Status '+httpRes.getStatus()+' and Status Code '+httpRes.getStatuscode();
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, errorMessage));
        }
    }
}

端点网址“https://api.linkedin.com/v2/people/~/connections”未获取连接数据。

【问题讨论】:

    标签: rest linkedin linkedin-api


    【解决方案1】:

    您收到错误消息,因为您的应用程序无权访问连接 API。此 API 不再可用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-20
      • 1970-01-01
      • 2022-12-30
      • 1970-01-01
      • 2022-12-25
      • 1970-01-01
      • 2018-02-24
      相关资源
      最近更新 更多