protected function _attach() { try { $sdk = new gl\SDK(); $session = null; if ($session = $sdk->obtainToken(Url::base('influencer/social/youtube/'), array(\Google_Service_YouTube::YOUTUBE_READONLY))) { $token = $session['refresh_token']; $sdk->setRefreshToken($token); $youtube = $sdk->getService('youtube'); $r = $youtube->channels->listChannels('snippet,statistics', array('mine' => 'true'))->getItems(); if (!count($r)) { throw new \Exception('Unable to fetch channel details'); } /** * @var $r \Google_Service_YouTube_ChannelListResponse */ $r = (array) $r[0]->toSimpleObject(); $r['refresh_token'] = $token; $influencer = new Influencer(UserSession::get('user._id')); $influencer->modify(array('_id' => $influencer->id), array('$set' => array('social.google-youtube' => $r), '$pull' => array('social_invalidated' => 'google-youtube'))); } } catch (\Google_Service_Exception $e) { Alert::once('error', 'Failed to add account: ' . $e->getMessage(), Url::base('influencer/social')); } Alert::once('success', 'Account added successfully', Url::base('influencer/social')); }
protected function _attach() { try { $sdk = new gl\SDK(); if ($session = $sdk->obtainToken(Url::base('brand/social/gplus/'), array(\Google_Service_Plus::PLUS_LOGIN, \Google_Service_Plus::PLUS_ME, \Google_Service_Plus::USERINFO_PROFILE))) { $token = $session['refresh_token']; $sdk->setRefreshToken($token); $plus = $sdk->getService('plus'); $me = (array) $plus->people->get('me')->toSimpleObject(); $me['refresh_token'] = $token; $brand = new Brand(UserSession::get('user._id')); $brand->modify(array('_id' => $brand->id), array('$set' => array('social.google-plus' => $me), '$pull' => array('social_invalidated' => 'google-plus'))); } } catch (\Google_Service_Exception $e) { Alert::once('error', 'Failed to add account: ' . $e->getMessage(), Url::base('brand/social')); } Alert::once('success', 'Account added successfully', Url::base('brand/social')); }
protected function _attach() { try { $sdk = new gl\SDK(); if ($session = $sdk->obtainToken(Url::base('influencer/social/analytics/'), array(\Google_Service_Analytics::ANALYTICS_READONLY))) { $token = $session['refresh_token']; $sdk->setRefreshToken($token); $analytics = $sdk->getService('analytics'); $accounts = array(); /** * @var \Google_Service_Analytics_Profile $f */ foreach ($analytics->management_profiles->listManagementProfiles('~all', '~all') as $f) { $name = $f['accountId'] . '-' . $f['webPropertyId'] . '-' . $f->getName(); $accounts[$name] = $f->toSimpleObject(); } $this->_display->view(array('main/app/influencer/social/analytics.php'), array('accounts' => $accounts, 'refresh_token' => $token)); } } catch (\Google_Service_Exception $e) { Alert::once('error', 'Failed to add account: ' . $e->getMessage(), Url::base('influencer/social')); } }