Google Calendar Event GoogleAuthIOException
I am trying to create a new Event
in Google Calendar. I also refered to the Calendar
sample App for creating an Event
and it's working fine if I create a new Calenda
r but when I tried to create a new Event
it is showing GoogleAuthIOExcepion
.
Here is My Code:
public class CSA extends ActionBarActivity
{
Button createEventBtn ;
Event createdEvent ;
GoogleAccountCredential credential;
com.google.api.services.calendar.Calendar client;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
credential = GoogleAccountCredential.usingOAuth2(this,
Collections.singleton(CalendarScopes.CALENDAR));
client = new com.google.api.services.calendar.Calendar.Builder(
transport, jsonFactory, credential).setApplicationName(
"CreateEventTestApp ").build();
createEventBtn = findViewById(R.id.button);
createEventBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
new MyTask(client).execute();
}
});
}
class MyTask extends AsyncTask<Void, Void, Event>
{
com.google.api.services.calendar.Calendar services;
public MyTask(com.google.api.services.calendar.Calendar service)
{
Log.v("Loading....", "Loading..." );
this.services = service;
}
@Override
protected Event doInBackground(Void... params)
{
Log.d("Service Event created", "Service Event created");
Event event = new Event();
event.setSummary("summary");
event.setLocation("place");
ArrayList<EventAttendee> attendees = new ArrayList<EventAttendee>();
attendees.add(new EventAttendee().setEmail("email");
event.setAttendees(attendees);
Date startDate = new Date();
Date endDate = new Date(startDate.getTime() + 3600000);
DateTime start = new DateTime(startDate,
TimeZone.getTimeZone("UTC"));
event.setStart(new EventDateTime().setDateTime(start));
DateTime end = new DateTime(endDate, TimeZone.getTimeZone("UTC"));
event.setEnd(new EventDateTime().setDateTime(end));
try {
createdEvent = client.events().insert("primary", event).execute();
} catch (IOException e) {
e.printStackTrace();
}
return createdEvent;
}
@Override
protected void onPostExecute(Event result) {
super.onPostExecute(result);
}
}
}
and the error it is showing is :
05-09 15:55:32.816: W/System.err(19365): com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAuthIOException
05-09 15:55:32.937: W/System.err(19365): at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:286)
05-09 15:55:32.937: W/System.err(19365): at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:859)
05-09 15:55:32.937: W/System.err(19365): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:410)
05-09 15:55:32.937: W/System.err(19365): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
05-09 15:55:32.941: W/System.err(19365): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
05-09 15:55:32.941: W/System.err(19365): at com.example.csa.csa$MyTask.doInBackground(CalendarSampleActivity.java:371)
05-09 15:55:32.941: W/System.err(19365): at com.example.csa.csa$MyTask.doInBackground(CalendarSampleActivity.java:1)
05-09 15:55:32.941: W/System.err(19365): at android.os.AsyncTask$2.call(AsyncTask.java:287)
05-09 15:55:32.945: W/System.err(19365): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
05-09 15:55:32.945: W/System.err(19365): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
05-09 15:55:32.949: W/System.err(19365): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
05-09 15:55:32.949: W/System.err(19365): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
05-09 15:55:32.953: W/System.err(19365): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
05-09 15:55:32.953: W/System.err(19365): at java.lang.Thread.run(Thread.java:856)
05-09 15:55:32.957: W/System.err(19365): Caused by: com.google.android.gms.auth.GoogleAuthException: BadUsername
05-09 15:55:33.109: W/System.err(19365): at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
05-09 15:55:33.109: W/System.err(19365): at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
05-09 15:55:33.113: W/System.err(19365): at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.getToken(GoogleAccountCredential.java:255)
05-09 15:55:33.113: W/System.err(19365): at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:279)
05-09 15:55:33.113: W/System.err(19365): ... 13 more
Please help if anyone already tried this.
链接地址: http://www.djcxy.com/p/76382.html上一篇: ExtJS和复杂的保存操作