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

  • Home
  • SEARCH
  • 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 8741309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:17:21+00:00 2026-06-13T11:17:21+00:00

I am wondering how I would convert this Google API JavaScript Sample code into

  • 0

I am wondering how I would convert this Google API JavaScript Sample code into an AngularJS app. I thought it would be really neat.

And as a follow-up how would it work with Oauth 2.0?

Thanks.

I tried using the angularjs seed app and modified it like this –

// controller.js

function SampleListCtrl ( $scope, $http ){
  $http.
  jsonp( 'https://apis.google.com/js/client.js?onload=JSON_CALLBACK' ).
  success( function () {
    alert( 'go go GO' );
    function makeRequest () {
    var request = gapi.client.urlshortener.url.get({
      'shortUrl': 'http://goo.gl/fbsS'
    });

   request.execute( function(response) {
       $scope.longUrl = response.longUrl;
     });
   }

    gapi.client.setApiKey( 'XXXX' );
    gapi.client.load( 'urlshortener', 'v1', makeRequest );

    $scope.samples = data.feed.entry;
  });
};

And in index.html

<div ng-controller="SampleListCtrl">
    <h4>{{ longUrl }}</h4>
</div>

RE: Roy Truelove’s tip I have tried adding an error callback which is firing

error( function () {
  console.log( JSON.stringify( arguments ) );
});

I wasn’t sure what would come back so I inspected the arguments object and so the output in the console is –

{"1":0,"3":{"method":"JSONP","url":"https://apis.google.com/js/client.js?onload=JSON_CALLBACK"}}

The alert does not fire meaning that the callback didn’t work. How do I get that to work? Is there a better approach?

  • 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-13T11:17:22+00:00Added an answer on June 13, 2026 at 11:17 am

    You are requesting JSON but load a javascript library, right? I don’t think the http service is made for that. You would need to either load the script before bootstrapping Angular or integrate a script loader to dynamically load it.

    If you are anyway using the Angular Seed template than you can just add the google API to the scripts in the index.html or use the asynchronous loader.

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

Sidebar

Related Questions

I'm wondering if there is a way to convert this so it would be
I was wondering what your opinion about this would be. I'm trying to convert
I'm trying to write a code that would convert letters into numbers. For example
I was wondering what the steps would be to convert a photo into a
I was wondering how I would convert a string of four to six digits
I'm new to MongoDB. Just wondering: How do I convert this shell command to
Basically I am wondering about having this behavior in an app where the newer
Afternoon all, I have this query and was wondering how i could convert this
I have a List<List<int>> . I would like to convert it into a List<int>
I was wondering what the neatest way would be to convert (from Python) a

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.