首页 > 解决方案 > 我已经使用 REST API 调用建立了与 LinkedIn 的连接。但是我在获取相关连接时遇到了这个问题

问题描述

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

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

公共无效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”未获取连接数据。

标签: restlinkedinlinkedin-api

解决方案


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


推荐阅读