Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9199139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:27:42+00:00 2026-06-17T22:27:42+00:00

I am new to CodeIgniter and PHP. Redirect URL given in Google API Console:

  • 0

I am new to CodeIgniter and PHP.
Redirect URL given in Google API Console:

Redirect URIs:  http://localhost/testsaav/index.php/main/gmail_invite

Following code shows me Request For Permission page. When I click Allow Access it takes me to

http://localhost/testsaav/index.php/main/gmail_invite?code=4/CXD462cen-oEBe1GaHIH90hjqb2X.QpVsg7mG4AUXaDn_6y0ZQNgaCVLxeAI

I want to redirect it to another page and show the response there. Controller method

function gmail_invites($data)
{
   $this->load->view('socialInvites2',$data);

}

View implementation

<?php 
            require_once APPPATH.'libraries/Google_Client.php';
            session_start();
            $client = new Google_Client();
            $client->setApplicationName('Google Contacts PHP Sample');
            $client->setScopes("http://www.google.com/m8/feeds/");
            $client->setClientId('xxx.apps.googleusercontent.com');
            $client->setClientSecret('xxx-xxx');
            $client->setRedirectUri('http://localhost/testsaav/index.php/main/gmail_invite');

            if (isset($_GET['code'])) {
              $client->authenticate();
              $_SESSION['token'] = $client->getAccessToken();
              $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
              header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
            }

            if (isset($_SESSION['token'])) {
             $client->setAccessToken($_SESSION['token']);
            }

            if (isset($_REQUEST['logout'])) {
              unset($_SESSION['token']);
              $client->revokeToken();
            }

            if ($client->getAccessToken()) {
              $req = new Google_HttpRequest("https://www.google.com/m8/feeds/contacts/default/full");
              $val = $client->getIo()->authenticatedRequest($req);
              //$xml = simplexml_load_string($val->getResponseBody());
              //$result = $xml->xpath('//gd:email');

              /*foreach ($result as $title) {
                echo $title->attributes()->address . "<br>";
              }*/
              // The contacts api only returns XML responses.
              $response = json_encode(simplexml_load_string($val->getResponseBody()));
              //print "<pre>" . print_r(json_decode($response, true), true) . "</pre>";

              // The access token may have been updated lazily.
              $_SESSION['token'] = $client->getAccessToken();
            } else {
              $auth = $client->createAuthUrl();
            }

            print "<a class='facebook-button' id='facebookbutton' href='$auth'>
            <span class='fb-button-left'></span>
            <span class='fb-button-center'>Invite GMail Friends</span>
            <span class='fb-button-right'></span></a>"; ?>
            <br/>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:27:43+00:00Added an answer on June 17, 2026 at 10:27 pm

    Why do you have all that php code in your view? That’s not how MVC works.

    Logic code should be kept in your Controller and not your View. I suggest that you use a Codeiginter OAuth2 library because the original code from Google’s OAuth2 lib isn’t meant to be compatible with Codeiginter or any other particular MVC framework. For example you could use this one: https://github.com/philsturgeon/codeigniter-oauth2

    You’re being redirected to the correct controller because the url is set here:

    $client->setRedirectUri('http://localhost/testsaav/index.php/main/gmail_invite');
    

    Also take a look at Codeigniter’s redirect method:
    redirect('somecontroller/some_method')

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I set my baseurl to: http://localhost/codeigniter/ in the application/config/config.php file as asked by the
I am new to PHP Codeigniter framework. I am designing a page in which
I am new in codeigniter, even in PHP. I want to upload a zipped
PHP/MySQL (CodeIgniter) I would like to add new interest_keywords in the exist database value.
I am fairly new to PHP and Codeigniter so im sure this will be
I am still new into Codeigniter framework. Today I read about Database Caching http://codeigniter.com/user_guide/database/caching.html
I have never before rewritten a URL except for removing the index.php part of
Im new to codeigniter and php, mysql and i am making a codeigniter app,
I am new to CodeIgniter, but not new to PHP, and I was wondering
I am pretty new to codeigniter. I do know php. How can I accomplish

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.