Google People API gapi.client.people.people.connections.list返回错误403,错误消息请求的身份验证范围不足,即使初始化包含所需范围
import java.util.Scanner;
public class wordRhombus {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter your name: ");
String name = sc.nextLine();
int enteredNamesLength = name.length();
for (int start = 0, stop = 0; start < enteredNamesLength && stop < enteredNamesLength; ) {
print(start, stop, name);
if (stop < enteredNamesLength - 1) {
stop++;
} else {
start++;
}
}
}
private static void print(int start, int stop, String name) {
for (int index = 0; index < name.length(); index++) {
if (index >= start && index <= stop) {
System.out.print(name.charAt(index));
} else {
System.out.print(" ");
}
}
System.out.println();
}
}
请求看起来像这样
gapi.client.init({
apiKey: '***masked***',
discoveryDocs: ["https://people.googleapis.com/$discovery/rest?version=v1"],
clientId: "***masked***.apps.googleusercontent.com",
'scope': "https://www.googleapis.com/auth/contacts.readonly"
});
等待登录更改
api.client.people.people.connections.list({
'resourceName': 'people/me',
'personFields': 'names,emailAddresses'
}).then(function (response) {
console.log(response.result.emailAddresses[0].value);
if (importGmailCallback) {
importGmailCallback(response);
}
}, function (reason) {
console.log('Error: ' + reason.result.error.message);
});
我在API Explorer中使用类似值成功,尝试删除访问权限并重新验证,删除了所有Cookie,但没有运气
答案 0 :(得分:1)
尝试删除范围内的引号。
<强>替换强>
&#39;范围&#39;:&#34; https://www.googleapis.com/auth/contacts.readonly&#34;
范围:&#34; https://www.googleapis.com/auth/contacts.readonly&#34;
答案 1 :(得分:0)
尝试添加此范围: &#34; https://www.google.com/m8/feeds&#34;