如何解决微信公众号开发转发接口,分享出去是链接不是卡片
I'd be happy to help you with that! ??As a WeChat public account developer, you may have encountered an issue where the shared link is not displayed as a card, but instead shows up as a plain text link. This can be frustrating, especially if you're trying to share rich content with your audience.
Before we dive into the solution, let's first understand the reason behind this issue. According to WeChat's documentation, when a public account shares a link using the `share` API, it will only display as a plain text link if the link is not properly formatted or if the domain is not whitelisted for open-domain access.
So, what can you do to resolve this issue? Here are some steps to help you get started:
Step1: Verify your public account's domain
Make sure that your public account's domain has been properly configured and verified with WeChat. This is a crucial step, as it allows WeChat to recognize your domain and enable open-domain access.
To verify your domain, follow these steps:
* Log in to the WeChat Developer Platform and navigate to the "Basic Information" section of your public account.
* Click on the "Domain" tab and enter your public account's domain (e.g., `example.com`).
* Save the changes and wait for the verification process to complete.
Step2: Use the correct share API format
When sharing a link using the `share` API, make sure that you're using the correct format. The format should include the following:
* A valid WeChat app ID (appid)
* A valid WeChat access token* The URL of the page you want to share* Optional: additional metadata such as title, description, and imageHere's an example of how you can use the `share` API in Python:
```pythonimport requestsappid = 'your_app_id'
access_token = 'your_access_token'
url = ' = {
'link': url,
'title': 'Page Title',
'description': 'Page Description',
'image': ' = {
'Authorization': f'Bearer {access_token}',
'Content-Type': 'application/json'
}
response = requests.post(' json=data, headers=headers)
print(response.json())
```
Step3: Add the link to your public account's custom menu
To display the shared link as a card, you need to add it to your public account's custom menu. This will allow WeChat users to view the shared content in a more visually appealing way.
Here's how you can do this:
* Log in to the WeChat Developer Platform and navigate to the "Menu" section of your public account.
* Click on the "Add Menu Item" button and enter the following information:
+ Title: The title of the menu item (e.g., "Shared Link")
+ Key: A unique key for the menu item (e.g., "shared_link")
+ URL: The URL of the page you want to share* Save the changes and wait for the update to take effect.
Step4: Test your shared link
Once you've added the link to your public account's custom menu, test it by sharing the link using the `share` API. You should see a card with the title, description, and image (if provided) when you share the link.
If you're still having issues, make sure that:
* Your public account's domain is properly configured and verified.
* The shared link is properly formatted and includes the required metadata.
* The custom menu item has been added correctly.
By following these steps, you should be able to resolve the issue of sharing links as plain text instead of cards. Happy coding! ??