dongzangchui2072 2014-07-17 13:27
浏览 45
已采纳

Yii登录问题在Facebook分享内容

I am stuck in a problem.

I have a Yii shopping cart only for registered users. I have added a facebook share button in it.
But when I am sharing any product, I am not able to get the product image or any details.
Instead I am getting the details from the login page.

I have checked the link in the facebook debug tool(https://developers.facebook.com/tools/debug).
It show

  • Fetched URL as original URL(URL for sharing and for fetching the contents)
  • Canonical URL as /user/login

Seems like the product page is checked but was redirected to the login page from where the details like og:url, og:type, og:title, og:image etc are called from the login page.

Is there any method to keep the authentication and allow the facebook to share the details? I think the problem can be solved within the Yii coding itself.

Thanking you in advance.

  • 写回答

1条回答 默认 最新

  • douyue3800 2014-08-23 10:18
    关注

    This is how sharing on facebook works:

    When you share a link on Facebook, Twitter or any such service, the service crawls the shared page URL for fetching the metadata.

    When you share an URL that is only accessible for authenticated users, there is no way for the crawlers to reach your URL. In Yii Framework, the request is redirected automatically to Login Page which is what the crawlers will see in your case.

    Here is how we solved it in one of our previous application:

    Added a different action for guest view for the particular page and redirect any non authenticated requests from main action to the guest view action. The guest view action will be similar to the main action except that the user will not be able do any actions here.

    Example:

    public function actionView(){
         if($isGues){
             //redirect to public function actionGuestview(){}
         }
         // Your Existing code to render the view file.
    }
    public function actionGuestView(){
         // Code to render the public view of the above action.
         // Make sure that the user cannot perform any actions here.
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 echarts动画效果失效的问题。官网下载的例子。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加