rest - 我已经使用 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”未获取连接数据。
解决方案
您收到错误消息,因为您的应用程序无权访问连接 API。此 API 不再可用。
推荐阅读
- xcode - 有什么方法可以弱添加 Swift 包?
- powerbi - 为 Power BI 中的多个相似列创建单个切片器
- beautifulsoup - 来自 CoinMarketCap w 类的 Web Scraping Table
- jquery - 为什么来自 ajax 响应的模态调用没有关闭?
- r - FCT_Collapse 使用范围
- google-apps-script - Google App Script - 使用 fetch 循环以获取 API 响应并写入电子表格
- spyder - 有没有办法让 Spyder 的 IPython 控制台仅显示标准输出并在调试期间隐藏“IPdb”消息?
- javascript - 如何在构造函数中等待?
- integer - PromptForInteger 问题
- reactjs - 将 React 应用程序部署到 github 页面正在发布一个空白页面