0

I have a Google form that requires the user to be logged in through Google to access the form. How can I access the form through the api? I have tried sending a get request to the form after logging in through the sample drive api gist(the one that uploads photos) but it still gives me a response code of forbidden.

This is from the Google quick start on GoogleSignIn:

// [START configure_signin]
    // Configure sign-in to request the user's ID, email address, and basic
    // profile. ID and basic profile are included in DEFAULT_SIGN_IN.

    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .requestScopes(new Scope("https://www.googleapis.com/auth/drive"), new Scope("https://www.googleapis.com/auth/plus.login"), new Scope("https://www.googleapis.com/auth/plus.me"), new Scope("https://www.googleapis.com/auth/forms"))
    // [END configure_signin]

    // [START build_client]
    // Build a GoogleApiClient with access to the Google Sign-In API and the
    // options specified by gso.

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();
    mGoogleApiClient.connect();
    // [END build_client]

This is from an AsyncTask that attempts to connect to the form(that requires sign in first:

public class RetrieveTokenTask extends AsyncTask<String, Void, String> {

Context mContext;

public RetrieveTokenTask(Context context){
    mContext = context;
}

@Override
protected String doInBackground(String... email) {

    try{
        URL api = new URL("https://docs.google.com/forms/d/___FORMID/formResponse?entry.209165355=1&entry.1433596447=1&entry.2073901950=1");

        HttpURLConnection conn = (HttpURLConnection) api.openConnection();
        conn.setRequestMethod("POST");
        conn.setInstanceFollowRedirects(true);
        conn.setRequestProperty("Authorization","Bearer " + GoogleAuthUtil.getToken(mContext,email[0],"oauth2:https://www.googleapis.com/auth/forms"));
        Log.wtf("Response", conn.getResponseCode()+"-"+conn.getResponseMessage());
        return null;

    }catch(Exception e ){
        Log.wtf("FAILED",e.getMessage());
    }

    return null;
}

}

shotgunsam
  • 75
  • 11
  • What `scopes` have you included? Have you looked around the community for similar posts like http://stackoverflow.com/questions/20372453/getting-a-403-forbidden-for-google-service-account and http://stackoverflow.com/questions/23520538/google-drive-api-403-forbidden and tried one of the solutions? – AL. Apr 05 '16 at 23:28
  • Hi, sorry it's been a while, I've been trying to learn more about the APIs. I've included the main googleapis.com/auth/drive but it seems to me that this api only allows me to view files in the user's drive, and not a public form like the one I'm trying to access. Any ideas? – shotgunsam Apr 28 '16 at 19:17
  • Can you post some code snippets? Have you completely implemented the google sign-in? – AL. May 06 '16 at 02:12
  • Yeah I have implemented it fully, I used the android QuickStart example from Google and get the token from that. I'll post the snippets tomorrow! – shotgunsam May 09 '16 at 04:27
  • @McAwesomville Finally got the code snippets up, could you take a look for me? – shotgunsam May 16 '16 at 04:38
  • Are you able to login properly? Were you able to get the response? – AL. May 16 '16 at 10:57
  • @McAwesomville I'm able to login properly, but the response is always 401-Unauthorized. Now that I think about it, this happens even when I login with the account that made the form. – shotgunsam May 17 '16 at 21:14
  • Hi. It's late, but have you successfully posted to Google Forms with logged in user? – uan Mar 20 '19 at 01:59

0 Answers0