Google Facebook Messenger 中不会显示静态地图

Google Static maps won't show in facebook messenger

将此发送到 facebook 将不会像以前那样显示地图

{
                    "attachment":
                    {
                        "type":"template",
                        "payload":
                        {
                            "template_type":"generic",
                            "elements":
                            [
                                {
                                    "title":"Is this your address?",
                                    "image_url":"https://maps.googleapis.com/maps/api/staticmap?size=400x400&markers=color:blue%7Clabel:S%7C"+address+"&key=API_KEY",
                                    "subtitle":address,
                                    "buttons":
                                    [
                                        {
                                            "type":"postback",
                                            "title":"Yes",
                                            "payload":address
                                        },
                                        {
                                            "type":"postback",
                                            "title":"No",
                                            "payload":"googlemapwrong"
                                        }              
                                    ]
                                }
                            ]
                        }
                    }

发送其他 image_url 仍然有效,但不显示地图。

facebook generic template documentation 中定义了

horizontal image aspect ratio is 1.91:1 and square image aspect ratio is 1:1 and Aspect ratio used to render images specified by image_url in element objects. Must be horizontal or square. Defaults to horizontal.

所以在你的情况下,我看到你正在尝试使用正方形的图像大小 400*400。所以你可以

  • try different size of image like 570*300 which is 1.9:1 image ratio

  • set image_aspect_ratio inside payload object as square and try your current image size.

希望对您有所帮助:)

Facebook 改变了他们解释链接的方式我想我正在连接的 'address' 变量必须针对 url 进行编码(空格应更改为 + 或 %20 等)。 Facebook 早些时候为我做这件事,但现在改变了。

正如@Abhishek Raj 所说,Fb 正在对 url 进行某种双重编码,然后 url 就没有意义了。我尝试先对 url 的地址进行编码,但随后地址保持解码状态并且 google 无法识别它。 我发现的唯一解决方法是从地址中删除特殊字符(例如#、@)(如果有的话),并将所有空格替换为破折号(google map doesn't mind if you do..)

address = address.Replace(' ','-')

然后使用url

中的地址
"image_url":"https://maps.googleapis.com/maps/api/staticmap?size=400x400&markers=color:blue%7Clabel:S%7C"+address+"&key=API_KEY"

这适用于 Messenger v2.2