【问题标题】:facebook share for custom parameters in a linkfacebook分享链接中的自定义参数
【发布时间】:2016-01-15 13:47:10
【问题描述】:

我正在尝试使用这个 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 上共享的链接时,用户应该被重定向到这个链接。忘记根 url,即 localhost:4000,因为在生产环境中它考虑了所需的 url。

问题是,当我在 facebook 上分享这个 url 时,用户被重定向到“http://localhost:4000/rings/solitaire-rings/lst?utf8”,并且它没有处理进一步的参数,即“%E2%9C%93&min_price=&max_price=&name=solitaire- ring&category=rings&fashion_type=false&search=&gallery_order=&new_arrival=&best_seller=&metal_white=on&commit=APPLY"

基本上我应该得到这个 URL "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]=Diamond&amp%3Bcommit=APPLY" ,它没有提供所需的输出。

【问题讨论】:

    标签: javascript ruby-on-rails


    【解决方案1】:

    这是我成功的做法

    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,它仍然有效!

    【讨论】:

    • 是否强制发送名称、字幕参数?因为我不想发送这些参数
    • 不,这只是可选的!
    • 嗯,检查你的 facebook 应用,它可能不允许本地主机!
    猜你喜欢
    • 2012-12-24
    • 2014-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-28
    • 1970-01-01
    • 1970-01-01
    • 2014-03-29
    相关资源
    最近更新 更多