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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:01:30+00:00 2026-05-30T14:01:30+00:00

While trying out Google’s Javascript API with Google+, I ran across a snag. var

  • 0

While trying out Google’s Javascript API with Google+, I ran across a snag.

var response;
var request = gapi.client.request({
    'path': '/plus/v1/people/' + "THEUSERID", 
    'params': {}});
request.execute(function(resp){});

The execute function (gapi.client.HttpRequest.execute) takes a single argument; a callback function. However, I do not wish to handle the data immediately after I receive it, I want to store it in the response variable I declared at the start of the code. Is there a way to use the callback argument to store the response?

Forgive me if this has an obvious solution, I’m a little new to JavaScript.

EDIT:
It has been suggested that the callback function be as follows:

request.execute(function(resp){response = resp;});

However, something curious happens with the function. Here is the code I used to test:

var response;
var request = gapi.client.request({
    'path': '/plus/v1/people/' + userID,
    'params': {}});
request.execute(function(resp){
    console.log("RESP:");
    console.log(resp);
    response = resp;});
console.log("RESPONSE:");
console.log(response);

What the console outputs is as follows:

RESPONSE:
undefined
GET https://www.googleapis.com/plus/v1/people/104815258973759324455?key=XXXXXXX
RESP:
({theactualjsondatathatIreceivedfromthecall})

Apparently, the code continues executing /before/ the execute callback function can be called. I need a way to check for this, so that the code after the execute function is not called until the callback function is run.

  • 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-05-30T14:01:32+00:00Added an answer on May 30, 2026 at 2:01 pm
    request.execute(function(resp){
      response = resp;
      afterExecute();
    });
    function afterExecute() {
      // this will not fire until after the response has been set.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While trying out an experimental UINavigationController-based iPhone application, I ran into a problem when
I am trying to run the Task-Android-sample given at Google Api Java Client I
While trying the google plus API example from the project site I'm completely stuck
I'm trying to get several informations from google calendar's API in JAVA. While trying
While trying problem 41 from the Euler Project, I ran across what seems to
I was hanging out in my profiler for a while trying to figure out
A while ago I was trying to figure out a way of doing this
My application times out while trying to connect to host. The timeout time is
I am trying to use Google language detection API, Right now I am using
I am trying to download some JSON from the google book API. The URL

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.