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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:29:03+00:00 2026-06-07T12:29:03+00:00

I’m using GWT and I want to make a JSONP request, which invokes a

  • 0

I’m using GWT and I want to make a JSONP request, which invokes a GWT method of mine when it returns.

However, I’m having trouble figuring out how to specify the GWT method to invoke on callback. Can anyone help? Here’s my example code:

private native void fetchUserData(String accessToken) /*-{
    var callback = "com.company.example.FacebookApi::handleUser";
    var url = "https://graph.facebook.com/me?access_token="+accessToken+"&callback=" + callback;

   // use jsonp to call the graph
   var script = document.createElement('script');
    script.src = url;
    document.body.appendChild(script);

  }-*/;

  public void handleUser(Object o) {
    Window.alert("Received object with class: " + o.getClass().getName())
  }

This code is ported from this example: Facebook Without SDK.

Alternatively, I just discovered there’s a GWT JsonpRequestBuilder which I haven’t had a chance to use yet, but if anyone can give an example without using any native code… then all the better.

Thanks!

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

    Figured it out, thanks in large part to these examples:

    Gwt + JSONP

    Cross Domain Requests with Gwt, Jsonp

    Cross site referenceing in GWT

    Here’s the updated code, per the comments (no callback specified, using Javascript Overlay Type)

      private void fetchDataUsingGwt() {
        String url = "https://graph.facebook.com/me?access_token=" + accessToken;
        JsonpRequestBuilder requestBuilder = new JsonpRequestBuilder();
        requestBuilder.requestObject(url, new AsyncCallback<FbUser>() {
      @Override
      public void onFailure(Throwable caught) {
        Window.alert(caught.getMessage());
      }
    
      @Override
      public void onSuccess(FbUser fbUser) {
          if (fbUser.isError()) {
            StringBuilder builder = new StringBuilder();
            builder.append("Fb error: ");
            builder.append(fbUser.getError().getMessage() + ", ");
            builder.append(fbUser.getError().getCode());
            String message = builder.toString();
            Window.alert(message);
            return;
          }
    
          StringBuilder builder = new StringBuilder();
          builder.append("Fetched user: " + fbUser.getFirstName() + " " + fbUser.getLastName());
          builder.append(" from " + fbUser.getHometown().getName());
          builder.append(" born on " + fbUser.getBirthday());
          builder.append(" with id " + fbUser.getId() + " and email " + fbUser.getEmail());
          builder.toString();
          String details = builder.toString();
          Window.alert("Got: " + details);
      }
    });
    

    }

    And the response is automatically wrapped using JSO like so:

      public class FbError extends JavaScriptObject {
        protected FbError() {
        }
    
        public final native String getMessage() /*-{
                return this.message;
        }-*/;
    
        public final native String getType() /*-{
                return this.type;
        }-*/;
    
        public final native String getCode() /*-{
                return this.code;
        }-*/;
    
        public final native String getSubCode() /*-{
                return this.error_subcode;
        }-*/;
    
      }
    
      public class Hometown extends JavaScriptObject {
        protected Hometown() {
        }
    
        public final native String getName() /*-{
                return this.name;
        }-*/;
    
        public final native String getId() /*-{
                return this.id;
        }-*/;
      }
    
      public class ErrorableJso extends JavaScriptObject {
    
        public boolean isError() {
          return getError() != null;
        }
    
        public final native FbError getError() /*-{
                return this.error;
        }-*/;
      }
    
      public class FbUser extends ErrorableJso {
    
        // TODO: Separate call needed to retrieve profile pic
    
        protected FbUser() {
        }
    
        public final native String getFirstName() /*-{
                return this.first_name;
        }-*/;
    
        public final native String getLastName() /*-{
                return this.last_name;
        }-*/;
    
        public final native String getId() /*-{
                return this.id;
        }-*/;
    
        public final native String getBirthday() /*-{
                return this.birthday;
        }-*/;
    
        public final native String getEmail() /*-{
                return this.email;
        }-*/;
    
        public final native Hometown getHometown() /*-{
                return this.hometown;
        }-*/;
      }
    

    For completeness, this is the raw JSON response the JSO wraps. Because of the inheritance, the same FbUser object is used if there’s either an error like so:

    {
       "error": {
          "message": "Error validating access token: Session has expired at unix time 1342044000. The current unix time is 1342050026.",
          "type": "OAuthException",
          "code": 190,
          "error_subcode": 463
       }
    }
    

    Or the expected User object:

    {
       "id": "23232323",
       "name": "Andrew Cuga",
       "first_name": "Andrew",
       "last_name": "Cuga",
       "link": "http://www.facebook.com/TheAndy",
       "username": "TheAndy",
       "birthday": "02/20/2011",
       "hometown": {
          "id": "108530542504412",
          "name": "Newark, Delaware"
       } // ... etc
    }
    

    Note the error and hometown fields in the JSON response are easily wrapped into JavaScriptObjects.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I am using parse_ini_file to read the contents of a file however it is
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I am reading a book about Javascript and jQuery and using one of 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.