我正在尝试向我的Cloud Endpoints添加身份验证,但我无法让它工作.我正在使用此博客作为指南:http://devthots.blogspot.nl/2012/07/building-awesome-android-apps-with.html
是)我有的:
在AppEngine项目中:
@Api(name = "noteendpoint", clientIds = { "123456789012-abcdefghijklmnopqrstuvwxyz012345.apps.googleusercontent.com" }, audiences = { "my_project_id.appspot.com" }, namespace = @ApiNamespace(ownerDomain = "example.com", ownerName = "example.com", packagePath = "myapp"))
public class NoteEndpoint {
// Rest of class, added parameter User to all methods.
}
Run Code Online (Sandbox Code Playgroud)
在我的Android应用项目中:
Note note = new Note();
note.setDescription("Description!");
GoogleAccountCredential credential =
GoogleAccountCredential.usingAudience(MainActivity.this, "my_project_id.appspot.com");
credential.setSelectedAccountName(ACCOUNT_NAME);
note.setEmailAddress(credential.getSelectedAccountName());
Builder endpointBuilder = new Noteendpoint.Builder(
AndroidHttp.newCompatibleTransport(),
new JacksonFactory(), credential);
Noteendpoint endpoint = CloudEndpointUtils.updateBuilder(endpointBuilder).build();
Note result = endpoint.insertNote(note).execute(); // Exception thrown …Run Code Online (Sandbox Code Playgroud)