Google日历事件GoogleAuthIOException

我正在尝试在Google日历中创建一个新Event 。 我也提到Calendar样本应用程序创建一个Event ,它工作正常,如果我创建一个新的Calenda r,但是当我尝试创建一个新的Event它显示GoogleAuthIOExcepion

这是我的代码:

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

    }

 }

}

它显示的错误是:

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):位于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):com.google.api.client.http.HttpRequest.execute(HttpRequest.java:859)

05-09 15:55:32.937:W / System.err(19365):位于com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:410)

05-09 15:55:32.937:W / System.err(19365):位于com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)

05-09 15:55:32.941:W / System.err(19365):位于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):在java.util.concurrent.FutureTask $ Sync.innerRun(FutureTask.java:305)

05-09 15:55:32.945:W / System.err(19365):在java.util.concurrent.FutureTask.run(FutureTask.java:137)

05-09 15:55:32.949:W / System.err(19365):在android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:230)

05-09 15:55:32.949:W / System.err(19365):在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)

05-09 15:55:32.953:W / System.err(19365):在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:569)

05-09 15:55:32.953:W / System.err(19365):在java.lang.Thread.run(Thread.java:856)

05-09 15:55:32.957:​​W / System.err(19365):引起:com.google.android.gms.auth.GoogleAuthException:BadUsername

05-09 15:55:33.109:W / System.err(19365):com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)

05-09 15:55:33.109:W / System.err(19365):com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)

05-09 15:55:33.113:W / System.err(19365):com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.getToken(GoogleAccountCredential.java:255)

05-09 15:55:33.113:W / System.err(19365):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更多

如果有人已经尝试过,请帮助。

链接地址: http://www.djcxy.com/p/76381.html

上一篇: Google Calendar Event GoogleAuthIOException

下一篇: check file exists java