标签: trustpilot

在 TrustPilot 小部件中自定义 JS/CSS

我正在尝试修改我网站上的 TrustPilot 小部件。

TrustPilot 小部件的基本结构是:

#tp-widget_wrapper .tp-widget-wrapper
    #wrapper-top .wrapper-top
        #tp-widget-reviews-wrapper .tp-widget-reviews-wrapper hidden-element
            #tp-widget-reviews .tp-widget-reviews
                .tp-widget-review
                    .tp-widget-stars
                    .date
Run Code Online (Sandbox Code Playgroud)

我试图隐藏 div .date

到目前为止我得到的是:

var trustpilot_children = document.getElementById("trustpilot_widget").childNodes;
var trustpilot_frame = trustpilot_children[0];
var date_tags = trustpilot_frame.document.getElementsByClassName("date");
date_tags.style.display = "none";
Run Code Online (Sandbox Code Playgroud)

但是我收到错误:

Uncaught TypeError: Cannot read property 'getElementsByClassName' of undefined
Run Code Online (Sandbox Code Playgroud)

var trustpilot_frame 正在查找 iframe,我只是无法访问其中的任何内容。

编辑

var trustpilot_children = document.getElementById("trustpilot_widget").childNodes;
var trustpilot_frame = trustpilot_children[0].contentDocument;
console.log(trustpilot_frame);
var date_tags = trustpilot_frame.getElementsByClassName("date");
console.log(date_tags);
date_tags.style.display = "none";
Run Code Online (Sandbox Code Playgroud)

安慰:

在此输入图像描述

编辑2

var trustpilot_children = document.getElementById("trustpilot_widget").childNodes;
var trustpilot_frame = trustpilot_children[0].contentDocument;
var style_tag …
Run Code Online (Sandbox Code Playgroud)

html javascript css dom trustpilot

4
推荐指数
1
解决办法
1万
查看次数

Trustpilot Api-“获得私有产品评论”始终返回未经授权的响应状态

我希望有一个人可以帮助我。

我正在尝试使用Trustpilot Api检索产品的产品评论,并取得了一些成功,但未获得我期望的结果。

我采用的方法如下:

  1. 获取一个OAUTH2令牌-(返回成功的响应)
  2. 从配置文件中检索我的业务部门,并为每个业务部门使用端点获取产品评论:-(https://api.trustpilot.com/v1/private/business-units/{business-unit}/review?token={OAUTH2 token from step 1}返回成功的响应)
  3. 对于每个产品评论,我尝试检索产品评论详细信息。为此,我有两个选择。

    (i)每个产品评论都有元链接,因此我可以使用相应的元链接并在apikey上加标签来获得产品评论,例如https://api.trustpilot.com/v1/reviews/1234567890abcdefg?apikey={apikey}apikey是我注册开发者帐户时提供的apikey-(返回成功响应)

    (ii)调用developers.trustpilot.api网站(https://developers.trustpilot.com/product-reviews-api#get-private-product-review)中记录的端点https://api.trustpilot.com/v1/private/product-reviews/{reviewId}:-(返回未经授权的状态码)

对于上面的选项(ii),我尝试了多种传递apikey的方法(根据文档,端点需要apikey作为授权。

我使用C#作为访问Trustpilot api的语言,因此以下代码段是我尝试调用该方法的方式。

  1. 如下设置GetProductReview端点:
    var url = $"https://api.trustpilot.com/v1/private/product-reviews/" + review.Id.ToString();        
    using (var client = new HttpClient())
    {
       var uri = new Uri(url, UriKind.Absolute);
       client.BaseAddress = uri;

       client.DefaultRequestHeaders.Clear();
       client.DefaultRequestHeaders.Accept.Add(new system.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
       client.DefaultRequestHeaders.Add("apikey", apiKey);

       try
       {
         var response = client.GetAsync(uri).Result;
             .
             .
             .
Run Code Online (Sandbox Code Playgroud)

在上面的代码片段中,将apikey传递给方法,并作为RequestHeader值传递给端点。

  1. 如下设置端点:
var url = $"https://api.trustpilot.com/v1/private/product-reviews/" + review.Id + $"?apikey={apiKey}";
Run Code Online (Sandbox Code Playgroud)

并按如下所示调用HttpClient:

  using (var client = new HttpClient())
  {
    var …
Run Code Online (Sandbox Code Playgroud)

api review unauthorized trustpilot

2
推荐指数
1
解决办法
111
查看次数

使用 JavaScript (jQuery) 插入时无法显示 TrustPilot HTML

如果我直接在 HTML 页面上添加 TrustPilot html 代码,它工作正常,但我需要使用 jQuery 插入它。我在插入时看到 HTML 代码,但没有显示。

  $(window).on('load', function () {
    var el = $('#some-element');

    el.html( trustPilotHtml() );

    function trustPilotHtml() {
      var str = "<div " +
        "class='trustpilot-widget' " +
        "data-locale='en-GB' " +
        "data-template-id='123456' "+
        "data-businessunit-id='123456' " +
        "data-style-height='500px' " +
        "data-style-width='100%' " +
        "data-theme='light' " +
        "data-stars='4,5' " +
        "data-schema-type='Organization'>" +
        "<a " +
        "href='https://some-url.com' target='_blank'>Trustpilot</a> " +
      "</div>";
      return $(str);
    }
});
Run Code Online (Sandbox Code Playgroud)

让元素正确显示的唯一方法是直接插入到 HTML 中而不使用 javascript?

javascript jquery trustpilot

1
推荐指数
1
解决办法
2670
查看次数

Next.js 中的 Trustpilot TrustBoxes

我正在尝试将 Trustpilot TrustBox 添加到 Next.js 应用程序。

我的 componentDidMount 中有这个:

 var trustbox = document.getElementById('trustbox');
 window.Trustpilot.loadFromElement(trustbox);
Run Code Online (Sandbox Code Playgroud)

这在我的脑海中:

<script type="text/javascript" src="//widget.trustpilot.com/bootstrap/v5/tp.widget.bootstrap.min.js" async></script>
Run Code Online (Sandbox Code Playgroud)

这在我的 html 中:

<div id="trustbox" className="trustpilot-widget" data-locale="en-GB" data-template-id="XX" data-businessunit-id="XX" data-style-height="130px" data-style-width="100%" data-theme="light" data-stars="5" data-schema-type="Organization">
    <a href="https://uk.trustpilot.com/review/XX" target="_blank">Trustpilot</a>
</div>
Run Code Online (Sandbox Code Playgroud)

这适用于热重载。例如,如果我在服务器运行时添加代码。但是 o 重新加载它会中断,我收到以下错误:

无法读取未定义的属性“loadFromElement”

有任何想法吗?

javascript reactjs trustpilot next.js

0
推荐指数
2
解决办法
1365
查看次数

标签 统计

trustpilot ×4

javascript ×3

api ×1

css ×1

dom ×1

html ×1

jquery ×1

next.js ×1

reactjs ×1

review ×1

unauthorized ×1