Xml model for adding contact to google contacts

2019-07-30 07:04发布

问题:

I try to write xml model by hand(as described in google-api-java-client site) to add contact to google contacts,but I have always got 400 bad request when trying to POST my contact,I have include all required fields to my model and try different possibilities but it doesn't work.Can anyone write single xml model to add contact with name and phone Number? This is my ContactEntry model:

public class ContactEntry
{
@Key
public Category category;

@Key("gd:name")
public Name name;

@Key
public String id;


@Key
public String title;

@Key
public Content content;

@Key("gd:phoneNumber")
public PhoneNumber phoneNumber;

}

Category class:

public class Category
{
@Key("@scheme")
public String scheme;

@Key("@term")
public String term;

public Category()
{
    this.scheme = "http://schemas.google.com/g/2005#kind";
    this.term = "http://schemas.google.com/contact/2008#contact";
}

}

Name class:

public class Name
{
@Key("@gd:givenName")
public String givenName;

@Key("@gd:familyName")
public String familyName;

@Key("@rel")
public String rel;

@Key("@fullName")
public String fullName;

public Name()
{
}

public Name(String givenName,String familyName)
{
    this.givenName = givenName;
    this.familyName = familyName;
    this.rel = "http://schemas.google.com/g/2005#other";//this is for test             
    this.fullName = givenName + familyName;
}

}