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;
}
}