在链接中分享自定义参数的脸书

facebook share for custom parameters in a link

本文关键字:参数 自定义 链接 分享      更新时间:2023-09-26

我正在尝试使用此JavaScript函数在Facebook上共享我的自定义链接,

function postToFacebook(title, summary, image_url, U) 
 {
   window.open('http://www.facebook.com/dialog/feed?app_id= ' + fb_app_id + '&display=popup&caption=' + title  + '&description='+ summary + '&redirect_uri=' + encodeURIComponent('http://facebook.com') + '&link=' + encodeURI(U) + '&picture=' + image_url,'sharer','toolbar=0,status=0,width=548,height=325');
 }

在我的"U"参数中,我有这个链接=>"http://localhost:4000/rings/solitaire-rings/lst?utf8=%E2%9C%93&min_price=&max_price=&name=solitaire-rings&category=rings&fashion_type=false&search=&gallery_order=&new_arrival=&best_seller=&metal_white=on&commit=APPLY"

当用户点击在Facebook上共享的链接时,用户应该被重定向到这个链接。 忘记根网址,即本地主机:4000,因为在生产环境中它考虑了所需的URL。

问题是我在Facebook用户上共享此URL的WHNE被重定向到"http://localhost:4000/rings/solitaire-rings/lst?utf8",并且它没有处理进一步的参数,即"%E2%9C%93&min_price=&max_price=&name=纸牌戒指&类别=戒指&fashion_type=false&搜索=&gallery_order=&new_arrival=&best_seller=&metal_white=on&commit=APPLY"

基本上我应该得到这个网址"http://admin.velvetcase.com/rings/lst?utf8=%E2%9C%93&min_price=&max_price=&name=rings&fashion_type=false&search=&gallery_order=&new_arrival=&best_seller=&search_material_id[]=Diamond&commit=APPLY",但是当我在Facebook上分享mu URL时,我得到了这个"http://admin.velvetcase.com/rings/lst?utf8=%E2%9C%93&amp%3Bmin_price&amp%3Bmax_price&amp%3Bname=rings&amp%3Bfashion_type=false&amp%3Bsearch&amp%3Bgallery_order&amp%3Bnew_arrival&amp%3Bbest_seller&amp%3Bsearch_material_id[0]=钻石&%3Bcommit=APPLY",这没有给出所需的输出。

这是我成功做到的

var sharingUrl = "https://www.facebook.com/dialog/feed?app_id="+ facebookAppID +
                 "&link=" + sharingUrl +
                 "&name=" + encodeURIComponent(title) +
                 "&caption=" + encodeURIComponent(caption) +
                 "&description=" + encodeURIComponent(content) +
                 "&picture=" + encodeURIComponent(thumb) +
                 "&redirect_uri=https://www.facebook.com";
window.open(sharingUrl);

对于我们需要使用encodeURIComponent的所有参数,但我尽量不使用encodeURIComponent进行sharingUrl,它仍然有效!