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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:44:39+00:00 2026-05-31T18:44:39+00:00

I have the below method: public String tryGoogleAuthentication(String auth_token){ ContactsService contactsService = new ContactsService(…..);

  • 0

I have the below method:

public String tryGoogleAuthentication(String auth_token){
    ContactsService contactsService = new ContactsService(".....");
    contactsService.setUserToken(auth_token);

    IFeed feed = null;
    try {
        feed = contactsService.getFeed(new URL("https://www.google.com/m8/feeds/  contacts/default/full?max-results=10000"), ContactFeed.class);
    } catch (IOException e) {
        e.printStackTrace();
        return CONST.GOOGLE_AUTH_INVALID_TOKEN;
    } catch (ServiceException e) {          
        e.printStackTrace();
        return CONST.GOOGLE_AUTH_INVALID_TOKEN;
    } catch (NullPointerException e) {
        e.printStackTrace();
        return CONST.GOOGLE_AUTH_INVALID_TOKEN;
    }

    if (feed == null)
        return "";

    String externalId = feed.getId();
    IPerson person = feed.getAuthors().get(0);
    String email = person.getEmail();
    String name = person.getName();
    String nameLang = person.getNameLang();

    System.out.println("externalId: " + externalId);
    System.out.println("email: " + email);
    System.out.println("name: " + name);
    System.out.println("nameLang: " + nameLang);

    return CONST.STATUS_OK;
}

and I get the error:

java.lang.NullPointerException: No authentication header information
at com.google.gdata.util.AuthenticationException.initFromAuthHeader(AuthenticationException.java:96)
at com.google.gdata.util.AuthenticationException.<init>(AuthenticationException.java:67)
at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:600)
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563)
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:552)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:530)
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535)
at com.google.gdata.client.Service.getFeed(Service.java:1135)
at com.google.gdata.client.Service.getFeed(Service.java:998)
at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:631)
at com.google.gdata.client.Service.getFeed(Service.java:1017)
at ro.servlet.data.ClientAuthenticator.tryGoogleAuthentication(ClientAuthenticator.java:96)
....

Please tell what shoud I set to contactsService(except setUserToken) in order to work proper?

I don’t used gData before(I’m an android/iPhone developer) – I took the auth string from the android device(by letting the user to confirm this) and pass it over a secured channel to my server – now I want to gather some data about this Contact(first, last name and provider uid – I need for a database with users in my app).

I really need to finish this task, so please, if anyone knows how this can be fixed, help me !

The below class describe the way I get the auth string from the android device.

package ro.locationsApp.android.login;

import java.io.IOException;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.params.HttpParams;
import org.json.JSONObject;
import ro.locationsApp.android.CONST;
import android.R;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AccountManagerCallback;
import android.accounts.AccountManagerFuture;
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class AccountList extends ListActivity {
protected AccountManager accountManager;
protected Intent intent;
DefaultHttpClient http_client = getThreadSafeClient();
private Account currentUsedAccount;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    accountManager = AccountManager.get(getApplicationContext());
    Account[] accounts = accountManager.getAccountsByType("com.google");
    String[] names = new String[accounts.length];
    for (int i = 0; i < accounts.length; i++) {
        System.out.println(accounts[i].name);
        names[i] = accounts[i].name;
    }

    this.setListAdapter(new ArrayAdapter<String>(this,
            R.layout.simple_list_item_1, names));
}

@SuppressWarnings("unchecked")
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    Account account = accountManager.getAccountsByType("com.google")[position];     
    accountManager.getAuthToken(account, "ah", false,
            new GetAuthTokenCallback(), null);
    currentUsedAccount = account;
}

public static DefaultHttpClient getThreadSafeClient() {
    DefaultHttpClient client = new DefaultHttpClient();
    ClientConnectionManager mgr = client.getConnectionManager();
    HttpParams params = client.getParams();

    client = new DefaultHttpClient(new ThreadSafeClientConnManager(params, 
            mgr.getSchemeRegistry()), params);


    return client;
}

@SuppressWarnings("rawtypes")
private class GetAuthTokenCallback implements AccountManagerCallback {

    public void run(AccountManagerFuture result) {
        Bundle bundle;
        try {
            bundle = (Bundle) result.getResult();
            Intent intent = (Intent) bundle.get(AccountManager.KEY_INTENT);
            if (intent != null) {
                // User input required
                startActivity(intent);
            } else {
                onGetAuthToken(bundle);                 
            }
        } catch (OperationCanceledException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (AuthenticatorException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
};

protected void onGetAuthToken(Bundle bundle) {
    final String auth_token = bundle.getString(AccountManager.KEY_AUTHTOKEN);
    System.out.println("AUTH TOKEN: " + auth_token);
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                JSONObject request = new JSONObject();
                request.put(CONST.ID_ATTR, CONST.ID_GOOGLE_AUTH);
                JSONObject body = new JSONObject();
                body.put(CONST.GOOGLE_AUTH_TOKEN, auth_token);
                request.put(CONST.DATA_ATTR, body);
                JSONObject response = new JSONObject(new RequestHandler().request(DataSource.LOCATIONS_SERVER_URL, request.toString()));
                String bodyResponse = response.optJSONObject(CONST.DATA_ATTR).optString(CONST.STATUS_ATTR);
                if(bodyResponse.equals(CONST.STATUS_OK)){

                }
                else if(bodyResponse.equals(CONST.GOOGLE_AUTH_INVALID_TOKEN)){
                    runOnUiThread(new Runnable() {
                        @SuppressWarnings("unchecked")
                        public void run() {
                            invalidateUserToken(auth_token);
                            accountManager.getAuthToken(currentUsedAccount, "ah", false,
                                    new GetAuthTokenCallback(), null);
                        }
                    });
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }).start();
}

public void invalidateUserToken(String token){
    AccountManager accountManager = AccountManager.get(this);
    accountManager.invalidateAuthToken("com.google", token);
}

}

Thanks,

Alex.

  • 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-31T18:44:41+00:00Added an answer on May 31, 2026 at 6:44 pm
    accountManager.getAuthToken(currentUsedAccount, "ah", false,
                                new GetAuthTokenCallback(), null);
    

    Your accountTokenType is wrong. The Contacts API scope is http://www.google.com/m8/feeds/ for v2 or https://www.google.com/m8/feeds/ for v3

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

Sidebar

Related Questions

I have the below program in MEF Method 1: public ObjectResult<PartnerListingStatement> GetCommissionListingRecords(string uRL, PortalConstant.DataSourceType
I have the below methods: public static byte[] ConvertFileToBytes(string filePath) { var fInfo =
I have this method: public static Expression<Func<MyEntity, bool>> MyMethod(string someId) { return o =>
i have class like below class Person { public string Name{get;set;} public string Surname{get;set;}
I'm calling the below method with 0.02 public static string FormatAsDecimalWithCommaSeperator(decimal value) { return
I have a WCF service and methods are exposed as below: public interface IService
I have the below method which is meant to append information to a file
I have a method to Generate Expression By Clause as below: internal static Expression<Func<TModel,
How can I select the good method (I have in the example below show
I have a class like this: public class Data { public string Name {

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.