Share WeChat Articles on LinkedIn
A step-by-step guide to bypassing domain restrictions and enhancing your LinkedIn content strategy.
WeChat (Weixin) Official Accounts Platform is a popular platform in the China market, extensively used by institutions and organizations to disseminate information. However, when you try to share WeChat articles on LinkedIn, such as adding an interview to your LinkedIn working experience or posting your team’s announcement, you may encounter issues.
Typically, LinkedIn might display error messages like, "Sorry, we were unable to retrieve information about your link. Please try another link," or "Cannot display preview. You can post as is, or try another link."
Understanding the Problem
These issues generally occur because LinkedIn has restrictions against certain domains, such as mp.weixin.qq.com
and *.workers.dev
. This results in LinkedIn being unable to fetch the necessary details from the link provided.
Seems the https://www.linkedin.com/voyager/api/graphql
API got nothing from the URL:
Solution Through Cloudflare Workers
The Cloudflare Workers platform enables you to deploy serverless code instantly across the globe through Cloudflare's data centers. With Cloudflare Workers, we can deploy a simple logic that bypasses LinkedIn’s domain restrictions.
We can use Workers to establish a reverse proxy that specifically handles requests from LinkedIn to access WeChat content, which means when a LinkedIn request is detected (User-Agent: LinkedInBot), then the proxy logic runs; otherwise, for regular users accessing, it should 301 redirect to the original WeChat article.
Let’s do it!
1. Set Up & Deploy a Cloudflare Worker
Register with Cloudflare, create a new worker, and insert the following code snippet:
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
/**
* Handle requests, redirect based on user agent or display content
* @param {Request} request
*/
async function handleRequest(request) {
const url = new URL(request.url);
let targetUrl = 'https://mp.weixin.qq.com/s';
// Check if the article ID is in the path or the query parameters
if (url.searchParams.has('__biz')) {
// If the URL contains query parameters, append the entire query string to the target URL
targetUrl += `?${url.searchParams}`;
} else {
// Otherwise, extract the article ID from the path
const path = url.pathname.split('/');
const articleId = path[path.length - 1];
targetUrl += `/${articleId}`;
}
const userAgent = request.headers.get('user-agent');
// Check if the user agent is LinkedInBot
if (userAgent && userAgent.includes('LinkedInBot/1.0')) {
// Display article content for LinkedInBot
const originalResponse = await fetch(targetUrl);
const originalText = await originalResponse.text();
// More content processing logic can be added here, such as HTML cleanup
return new Response(originalText, {
headers: { 'content-type': 'text/html;charset=UTF-8' }
});
} else {
// Redirect non-LinkedIn user agents to the original article
return Response.redirect(targetUrl, 301);
}
}
2. Domain Binding for Your Worker
Since the *.workers.dev
were blocked by LinkedIn, you need to using your custom domains for this service. Navigate to your Worker settings, then to Triggers, and add a subdomain from your account:
Wait for the issuance of a domain certificate, which should display 'Active' once ready.
3. Replace with your Worker URL.
Replace the mp.weixin.qq.com
part of the WeChat link with your custom domain. For example, replace:
https://mp.weixin.qq.com/s/dekkArgbpMDrZw-_rUKIGQ
to:
https://mp.3588837.xyz/s/dekkArgbpMDrZw-_rUKIGQ
The new URL should successfully display the content preview on LinkedIn:
4. Using My Workers’ URL
Alternatively, if you prefer not to set up your own service, you can use the one I have prepared by simply replacing
mp.weixin.qq.com
with:
mp.cheng.lu
By implementing this workaround using Cloudflare Workers, you can enhance your LinkedIn profile’s engagement and ensure your audience has access to critical WeChat content without disruptions.
奇怪了, APP明明显示评论失败,结果每一条都发上来了
great tutoriall