Google分析API分页当前页码和下一页认证 [英] Google analytics API pagination current page number and nextpage authentication

查看:122
本文介绍了Google分析API分页当前页码和下一页认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为wordpress开发一个分析插件,我已经获得了我所需的数据,但时间太长了,所以我想在这里使用分页。

I am developing a analytics plugin for wordpress, I have got my required data but It is too long, so I want to use pagination here.


如果我尝试进入下一个链接(在
下面的代码中使用 getNextLink()),它会向我显示一个错误,这是

if I will try to get into next link( using getNextLink() ) on the below code it will show me an error that, this is unauthenticated.

我如何验证它并在下一页显示下一个结果集。我在插件设置页面显示结果。

How I can authenticate it and show the next resultset on the next page . I am displaying the result on plugin setting page.


另一个重要的事情是是否有任何函数或方法可以获得
当前页码?

And another important thing is "Is there any function or way to get the current page number ?"

我正在添加屏幕截图,如果需要其他任何详细信息来指导我,请告诉我。

I am adding the screenshot, If any other details required to guide me on this , please let me know.

你可以看到有1到30,我写了一个,但对于下一页,它需要改变,我不知道如何获得当前页码。

You can see there is "1 to 30", I have written that one, but for the next page, it need to be changed, I have no idea how I can get the current page number .

返回这个分页的函数是: -

The function that will return this pagination is :-

public  function getPaginationInfo(&$results) {

print '<div class="tablenav-pages"><span class="displaying-num">' . $results->getTotalResults() . ' items</span>
<span class="pagination-links"><span class="tablenav-pages-navspan" aria-hidden="true">«</span>
<a class="prev-page" href="' . $results->getPreviousLink() . '"><span class="screen-reader-text">Previous page</span><span aria-hidden="true">‹</span></a>
<span class="screen-reader-text">Current Page</span><span id="table-paging" class="paging-input">' . 1 . ' of <span class="total-pages">' . ceil($results->getTotalResults()/10) . '</span></span>
<a class="next-page" href="' . $results->getNextLink() . '"><span class="screen-reader-text">Next page</span><span aria-hidden="true">›</span></a>
<span class="tablenav-pages-navspan" aria-hidden="true">»</span></span></div>';

    }


推荐答案

accessToken添加到下一个和上一个链接,并使用AJAX进行分页。

I added accessToken to the next and previous link and used AJAX for pagination.

$ results-> getNextLink()。 &安培; =的access_token。 $ accessToken 这是实现这一点的关键。

$results->getNextLink() . '&access_token='. $accessToken this is the key to achieve this.

$accessToken = json_decode($_SESSION['access_token'])->access_token;
print '<div class="tablenav-pages"><span class="displaying-num">' . $results->getTotalResults() . ' items</span>
<span class="pagination-links"><span class="tablenav-pages-navspan" aria-hidden="true">«</span>
<a class="prev-page" href="' . $results->getPreviousLink() . '&access_token='. $accessToken . '"><span class="screen-reader-text">Previous page</span><span class="tablenav-pages-navspan" aria-hidden="true">‹</span></a>
<span class="screen-reader-text">Current Page</span><span id="table-paging" class="paging-input">' . 1 . ' of <span class="total-pages">' . ceil($results->getTotalResults()/10) . '</span></span>
<a class="next-page" href="' . $results->getNextLink() . '&access_token='. $accessToken . '"><span class="screen-reader-text">Next page</span><span class="tablenav-pages-navspan" aria-hidden="true">›</span></a>
<span class="tablenav-pages-navspan" aria-hidden="true">»</span></span></div>';

和ajax部分大致

and ajax part roughly

jQuery('document').ready(function(){
    jQuery('.next-page').click(
        function( event ){
            event.preventDefault();

            url = jQuery(this).attr('href');
            jQuery.ajax({
                url: url,
                context: document.body
            }).done(function( data ){
                console.log( data );
            });

        });
});

这篇关于Google分析API分页当前页码和下一页认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆