具有打开图形自定义标题,图像,描述不显示的Facebook共享(Magento 2)

问题描述 投票:0回答:1

我正在尝试在Magento 2中运行开放图共享。共享网址时如下所示:https://www.facebook.com/v6.0/dialog/share_open_graph?action_properties=%7B%22object%22%3A%7B%22og%3Aurl%22%3A%22http%3A%2F%2FXXXX.XXXX.XX%3A8005%2Fde%2Fmini-taschenschirm-filigrain.html%22%2C%22og%3Atitle%22%3A%22Test%20Titel%22%2C%22og%3Adescription%22%3A%22test%20description%22%2C%22og%3Aimage%3Aurl%22%3A%22http%3A%2F%2FXXX.XXXXX.XX%3A8005%2Fpub%2Fmedia%2Fcatalog%2Fproduct%2Fcache%2Faec5383cda2d6e7ccc1547d0d0cdcbe8%2Fs%2Fc%2Fschirm_black_1.jpg%3E%22%7D%7D&action_type=og.shares&app_id=1355337027998409&channel_url=https%3A%2F%2Fstaticxx.facebook.com%2Fconnect%2Fxd_arbiter.php%3Fversion%3D46%23cb%3Df2d86ce06c7e8a4%26domain%3Dmage.intermall.de%26origin%3Dhttp%253A%252F%252FXXX.XXXX.XX%253A8005%252Ff37eea29d1c7654%26relation%3Dopener&display=popup&e2e=%7B%7D&fallback_redirect_uri=http%3A%2F%2FXXX.XXXX.XX%3A8005%2Fde%2Fmini-taschenschirm-filigrain.html%23&locale=en_US&next=https%3A%2F%2Fstaticxx.facebook.com%2Fconnect%2Fxd_arbiter.php%3Fversion%3D46%23cb%3Df3e4e25677030d%26domain%3Dmage.intermall.de%26origin%3Dhttp%253A%252F%252FXXX.XXXX.XX%253A8005%252Ff37eea29d1c7654%26relation%3Dopener%26frame%3Df10ab084fc6bbf%26result%3D%2522xxRESULTTOKENxx%2522&sdk=joey&version=v6.0

我的功能看起来像这样:

define([
    'jquery',
    'underscore'
], function ($, _) {
    'use strict';

    $.widget('intersales.shareFB', {
        options: {
            url: null,
            quote: null,
            img: null
        },
        _create: function(){
            var self = this;
            self._bindSubmit();
        },
        _bindSubmit: function () {
            var self = this;
            $(this.element).click(function(e){
                e.preventDefault();
                self._share();
            });
        },
        _share: function(){
            console.log('sharing url' + ' ' + this.options.url);
            console.log('sharing img' + ' ' + this.options.img);
            var self = this;
            FB.ui({
                method: 'share_open_graph',
                action_type: 'og.shares',
                action_properties: JSON.stringify({
                    object: {
                        'og:url': this.options.url,
                        'og:title': 'Test Titel',
                        'og:description': 'test description',
                        'og:image:url': this.options.img
                    }
                })
            }, function(response){
                if (response && !response.error_message) {
                    // then get post content
                    alert('successfully posted. Status id : '+response.post_id);
                } else {
                    console.log('Something went error.');
                }
            });
        }
    }
    );
    return $.intersales.shareFB;
});

有趣的是,共享时链接正确,但未显示图像,标题或描述。我有点不想在页面中设置oh标签,因为它的magento和我都不想覆盖现有的模板。

我是magento的新手,并且想要/需要编写一个模块,该模块可以在产品详细信息页面中实现社交媒体共享。我的目标是通过Twitter和Facebook做到这一点。我开始为facebook做那件事,但是有点太复杂了。我要分享的是带有自定义文字,标题和产品图片的产品(也许有标签)谁能让我走上正确的路?

javascript facebook magento facebook-opengraph share-open-graph
1个回答
0
投票

那些参数不再适用于动态OG标签,它们只是较早的一种解决方法。更改OG标签以进行共享的唯一方法是在原始页面源中进行更改。 Facebook会自动将其提取。

© www.soinside.com 2019 - 2024. All rights reserved.