0

我正在尝试使用 Code Igniter 连接到 Google Analytics,我有以下代码但无法正常工作

class Google_analytics_model extends CI_Model
{   
    public function __construct()
    {
        parent::__construct();
        $this->load->library('analytics', array('username' => $this->settings->ga_email, 'password' => $this->settings->ga_password));
        $this->analytics->setProfileById('ga:' . $this->settings->ga_profile_id);
        $this->set_month(time());
    }

    public function get_by_type($type = 'overview')
    {
        try
        {
            switch($type)
            {
                case "overview":
                    return $this->_overview();
                    break;
                case "referrers":
                    return $this->_referrers();
                    break;
                case "keywords":
                    return $this->_keywords();
                    break;
                case "top_content":
                    return $this->_top_content();
                    break;
                case "visits_by_country":
                    return $this->_visits_by_country();
                    break;
                case "browsers":
                    return $this->_browsers();
                    break;
                case "screen_resolutions":
                    return $this->_screen_resolutions();
                    break;
            }
        }
        catch(Exception $e) 
        {
            return '<p class="error">Unable to connect to Google Analytics. Please ensure your <a href="' . site_url(ADMIN_PATH . '/settings/general-settings') . '">analytic settings</a> are correct.</p>';
        }
    }

我输入了正确的电子邮件和密码,但出现错误

Unable to connect to Google Analytics....

如何连接和获取数据?

谢谢

4

0 回答 0