我试图使用get和list方法来使用Google plus comment。在官方网站中,它表示(所有的API调用都需要一个OAuth 2.0令牌或一个API密钥。)并且我尝试了发送GET请求,而没有使用OAuth步骤,它可以工作,它返回json格式数据。我的问题是,在使用Google + API之前,OAuth必须要求吗?在使用Google + API之前必须使用OAuth
0
A
回答
1
这取决于您正在尝试获取的数据。
https://developers.google.com/+/api/oauth记录了使用OAuth的好处,但一般情况下,如果您想要获取私人个人资料数据,或者希望使用/ me/URL快捷方式,则需要使用OAuth,并且可能,另外使用一个App Key。如果您对所有感兴趣的都是公共数据,则可以使用应用程序密钥。
1
您是否可以做到这一点的简短答案是您可以在没有OAuth的情况下从Google+获得评论。
至于你怎么做到这一点,我不确定你在做什么,但下面的代码显示了这是如何在JavaScript中完成的。
这里使用的API调用可以在API浏览器直接尝试:
您需要使用来自Google APIs console的Google+ API的项目的API密钥(简单密钥)。设置项目时,您只需从服务部分启用Google+ API即可。
首先,使用公共数据API抢活动:
// Gets the activities for a profile
function getActivities(profileID){
var activities = null;
var URL = "https://www.googleapis.com/plus/v1/people/" + profileID + "/activities/public?alt=json&key=" + key;
var request = new XMLHttpRequest();
request.open('GET', URL, false);
request.send(); // because of "false" above, will block until the request is done
// and status is available. Not recommended, however it works for simple cases.
if (request.status === 200) {
if (debug) console.log("retrieved activities \n\n");
var activities = jQuery.parseJSON(request.responseText).items;
console.log("Discovered " + activities.length + " activities");
}else{
handleRequestIssue(request);
}
return activities;
}
下面的代码遍历活动
for (var i=0; i < activities.length; i++) {
console.log("trying to do something with an activity: " + i);
var activity = activities[i];
console.log(activity.id);
}
接下来,你可以使用活动ID检索每个活动的意见:
function getCommentsForActivity(activityID){
var comments = "";
var URL = "https://www.googleapis.com/plus/v1/activities/" + activityID + "/comments?alt=json&key=" + key;
var request = new XMLHttpRequest();
request.open('GET', URL, false);
request.send(); // because of "false" above, will block until the request is done
// and status is available. Not recommended, however it works for simple cases.
if (request.status === 200) {
if (debug) console.log(request.responseText);
var comments = jQuery.parseJSON(request.responseText).items;
if (debug){
for (comment in comments){
console.log(comment);
}
}
}else{
handleRequestIssue(request);
}
return comments;
}
function manualTrigger(){
var activities = getActivities("109716647623830091721");
}
以下代码将它汇集在一起并检索活动和评论的具体职位:
$(document).ready(function() {
var renderMe = "";
var activities = getActivities("109716647623830091721");
console.log("activities retrieved: " + activities.length);
for (var i=0; i < activities.length; i++) {
console.log("trying to do something with an activity: " + i);
var activity = activities[i];
renderMe += "<br/><div class=\"article\"><p>" + activity.title + "</p>";
console.log(activity.id);
// get comments
var comments = getCommentsForActivity(activity.id);
for (var j=0; j<comments.length; j++){
renderMe += "<br/><div class=\"comment\">" + comments[j].object.content + "</div>";
}
renderMe += "</div>";
}
console.log("I'm done");
document.getElementById("ac").innerHTML = renderMe;
});
+0
这是伟大的,因为在JavaScript中的同源策略我不确定代码可以工作,但无论如何感谢您的帮助 – user1961278
相关问题
- 1. 为什么我必须在使用Google+ API API结果集之前使用JSON.stringify .parseJSON?
- 2. 使用Appengine的Google API(OAuth)
- 3. 您必须在Android上使用Parse库之前调用Parse.initialize()
- 4. 必须在getParameter之前调用MultipartConfig getPart
- 5. Magnific Popup - 必须在iframe中使用Google地图嵌入API
- 6. “必须在iframe中使用Google Maps Embed API。”
- 7. 在Google Calendar API中使用OAuth PHP库
- 8. 在Android中使用Google API与OAuth 2.0
- 9. oAuth使用PHP(适用于google api)
- 10. 在使用错误之前项目集合必须为空
- 11. 必须在使用DataView之前设置DataTable
- 12. 错误“在使用之前必须设置UnitOfWorkManager”
- 13. 在使用之前,类函数/变量是否必须声明?
- 14. 之前必须调用“WebSecurity.InitializeDatabaseConnection”方法吗?
- 15. Google Buzz API OAuth问题 - 使用Zend_OAuth(PHP)
- 16. 使用Java的Google Data API中的OAuth
- 17. perl中的任何Google API使用OAuth
- 18. Google oauth使用js api获取refresh_token
- 19. 不能使用Sharekit。 “ShareKit必须在使用前配置”
- 20. 在Android上使用OAuth 2.0使用Google API的最佳方式
- 21. WPF错误:“使用ItemsSource之前,项目集合必须为空。”
- 22. DataGridTemplateColumn:使用ItemsSource之前,项目集合必须为空。
- 23. 项目必须为空之前使用showdialog项目源
- 24. 使用AirDrop之前,我们必须下载远程文件吗?
- 25. 项目集合必须为空之前使用itemssource - datagrid wpf
- 26. 在WP7上使用Google oAuth
- 27. 在使用DownloadCache之前,您必须在File插件上调用EnsureLoaded
- 28. OpenFileDialoug当前线程在OLE调用之前必须是STA
- 29. Xamarin表单错误 - '您必须调用Xamarin.Forms.Init();在使用它之前' - TestFlight(iOS)only
- 30. 在YouTube上使用Oauth api
我只想从谷歌+评论是否意味着我可以跳过OAuth的一部分。 Google Plus的标志看起来不相关? – user1961278