我尝试在我的客户端项目中实现 LinkedIn API,并尝试创建一个具有身份验证功能的应用程序 (OAuth)。 使用该令牌,我从 Postman 访问了 ugcPosts API,但它是相同的。我无法访问 jQuery。
要使 LinkedIn API 在我的应用程序中运行需要采取什么步骤?
要从您的应用程序访问 LinkedIn API,您需要执行以下步骤:
创建 LinkedIn 开发者应用程序:
获取您的客户ID和客户秘密:
实施OAuth 2.0身份验证:
使用 API 请求的访问令牌:
Authorization
标头中。以下是如何使用 jQuery 使用访问令牌发出 API 请求的示例:
var accessToken = 'YOUR_ACCESS_TOKEN';
$.ajax({
url: 'https://api.linkedin.com/v2/ugcPosts', // Example endpoint, replace with the desired LinkedIn API endpoint.
method: 'GET', // Specify the HTTP method (GET, POST, etc.).
headers: {
'Authorization': 'Bearer ' + accessToken // Include the access token in the Authorization header.
},
success: function(data) {
// Handle the response data from LinkedIn API.
console.log(data);
},
error: function(xhr, status, error) {
// Handle errors, if any.
console.log('Error: ' + error);
}
});
Make sure to replace `'YOUR_ACCESS_TOKEN'` with the actual access token obtained through the OAuth 2.0 authentication flow. Additionally, replace the URL with the specific LinkedIn API endpoint you want to access.
Remember to review LinkedIn's API documentation for detailed information on the available endpoints, required parameters, and response formats. LinkedIn's API also requires certain permissions for different types of data access, so ensure that your app has the necessary permissions to access the UGC posts or other data you need.