问题描述
我已使用REST API调用在Salesforce和LinkedIn之间建立了连接。但是我在将相关的连接和网络数据提取到Salesforce时遇到了问题。
据我所知,我的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”未获取连接数据。
解决方法
您收到错误消息,因为您的应用程序无法访问连接API。此API不再可用。