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 8645153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:28:32+00:00 2026-06-12T12:28:32+00:00

I use oauth of google to access user data, and this is my function.

  • 0

I use oauth of google to access user data, and this is my function.

    public function actionOauth2callback(){
    $client_key = 'client-key-here';
    $client_secret = 'client-secret-here';
    $api_key = 'api-key';
    $redirect_uri = 'http://localhost:8888/proj/user/oauth2callback';

    if (!isset($_REQUEST['code']) && !isset($_SESSION['access_token'])) {
            // Print the below message, if the code is not received !
        echo "Please Authorize your account: <br />";
        echo '<a href = "https://accounts.google.com/o/oauth2/auth?client_id='. $client_key. '&redirect_uri='.$redirect_uri .'&scope=https://www.googleapis.com/auth/plus.me&response_type=code">Click Here to Authorize</a>';
    }
    else {
        if(!isset($_SESSION['access_token'])) {
          // Initialize a cURL session
            $ch = curl_init();

              // Set the cURL URL
              curl_setopt($ch, CURLOPT_URL, "https://accounts.google.com/o/oauth2/token");

              // The HTTP METHOD is set to POST
              curl_setopt($ch, CURLOPT_POST, TRUE);

              // This option is set to TRUE so that the response
              // doesnot get printed and is stored directly in 
              // the variable
              curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

              // The POST variables which need to be sent along with the HTTP request
              curl_setopt($ch, CURLOPT_POSTFIELDS, "code=" . $_REQUEST['code'] . "&client_id=" . $client_key . "&client_secret=" . $client_secret . "&redirect_uri=".$redirect_uri."&grant_type=authorization_code");

              // Execute the cURL request       
              $data = curl_exec($ch);

              // Close the cURL connection
              curl_close($ch);
              // Decode the JSON request and remove the access token from it
              $data = json_decode($data);

              $access_token = $data->access_token;

              // Set the session access token
              $_SESSION['access_token'] = $data->access_token;
        }
        else {
          // If session access token is set
            $access_token = $_SESSION['access_token'];
        }
        // Initialize another cURL session
        $ch = curl_init();

        // Set all the options and execute the session
        curl_setopt($ch, CURLOPT_URL, "https://gdata.youtube.com/feeds/api/users/default?v=2&access_token=" . $access_token);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        $data = curl_exec($ch);
        curl_close($ch);
        // Get the data from the JSON response
        print_r($data);         
        $data = json_decode($data);
        print_r($data);
    }

But I have problem with format of data response, it’s not JSON or XML, just string like this

tag:youtube.com,2008:user:JNbz_VZ2LG1WD4zjKEY9uQ2010-06-02T13:11:26.000Z2012-09-29T20:32:13.000ZHuyTranHoanghttps://gdata.youtube.com/feeds/api/users/chenhuanghuiJNbz_VZ2LG1WD4zjKEY9uQ22HuymTran HoangVNJNbz_VZ2LG1WD4zjKEY9uQchenhuanghui

Anybody can tell me, what wrong am I?
Thank you so much

  • 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-12T12:28:35+00:00Added an answer on June 12, 2026 at 12:28 pm

    All Google Data APIs support JSON output through the use of the alt parameter You need to Look at Developer’s Guide: JSON / JavaScript

    Your URL should look like this

    http://gdata.youtube.com/feeds/api/standardfeeds/most_popular?v=2&alt=json
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying to use Google OAuth to import a user 's contacts. In
I am using Google's Oauth 2.0 to get the user's access_token, but I dont
I am using the Google Client API and the GoogleAuthUtil.class to get access to
I'm trying to access an OAuth-protected resource on Google App Engine using a Java/Groovy
I'm trying to use Google's Custom Search API through the Google API Ruby client
I am attempting to use oauth API to authenticate a google service account through
I got a little problem with the OAuth for Google, I use the Jim
I'm using Java with Google Plus API. I'm using OAuth 2.0. When a user
I'm currently using OAuth 2.0 to access the Google API. From my understanding, I
This is with reference to using Google Contacts Data API. It requires that the

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.