开始使用Microsoft Academic Graph API

时间:2018-06-17 11:08:15

标签: web-services azure microsoft-cognitive academic-graph

我正在尝试使用their API在Microsoft Academic Graph上运行一些查询。我无法弄清楚Ocp-Apim-Subscription-Key的用途。 (我看过this question并没有帮助。)当我尝试运行查询时,我收到以下消息(401:拒绝访问):Access denied due to invalid subscription key. Make sure you are subscribed to an API you are trying to call and provide the right key.。这可以在命令行上使用curl:

curl -v -X GET "https://westus.api.cognitive.microsoft.com\
/academic/v1.0/evaluate?\
expr=stochastic&model=latest&count=10&offset=0&attributes=Id" \
-H "Ocp-Apim-Subscription-Key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

或使用API testing console

那么我在Ocp-Apim-Subscription-Key使用的是什么? (不是很多X!)我尝试了两件事。首先,我尝试使用您可以获得的密钥,转到https://labs.cognitive.microsoft.com/en-us/project-academic-knowledge并单击订阅链接(密钥1或密钥2)。

其次,我尝试使用通过转到cognitive services on my azure portal生成的密钥,并尝试创建对合适服务的订阅。但是,我看不到任何与我想要使用的Academic Search API相匹配的内容,因此我使用了通用的bing搜索订阅。

这些都不允许我访问API。我错过了什么?

修改

在@ ali-heikal的第一次回复后,我尝试去了这里:https://dev.labs.cognitive.microsoft.com/docs/services/56332331778daf02acc0a50b/operations/5951f78363b4fb31286b8ef4/console。页面顶部会显示一个红色警告框:You are not subscribed to this API and will get a '401 Access Denied' response. To subscribe, go to the Products page and click on the desired product containing this API.。如果我转到“产品”页面,然后转到Project Academic Knowledge - Preview页面,我将有机会订阅。单击订阅会将我带到一个通用的MS登录(我已登录,选择该帐户),我被带到一个页面上说:

  

我们无法完成您的请求   Microsoft帐户遇到技术问题。请稍后再试。

所以这对我不起作用。在哪里记录我应该使用此端点?有人可以提供有关如何使用它的进一步说明吗?

EDIT2:

这个答案描述了使用不同的端点:https://stackoverflow.com/a/49318405/54557。但是,更改我的curl请求以使用它不起作用(具有相同的拒绝访问错误)。

1 个答案:

答案 0 :(得分:1)

您使用的是错误的端点,因为您使用的是预览API,因此您也应该使用Preview endpoint

如果您遵循这些步骤,它应该有效:

  • here重新生成密钥(此次不要使用旧密钥),然后点击是,重新生成此密钥按钮确认
  • here
  • 打开测试控制台
  • 将您刚刚生成的密钥插入 Ocp-Apim-Subscription-Key 字段
  • 将以下内容插入请求正文字段:import java.util.Arrays; import java.util.List; public class Test { public static void main(String... args){ // Sample String sentence String sentence = "This is the sentence with 5 words starting with all like allwords alltogether also Allnotout allother and allofus."; // Splitting above sentence to get each word separately and storing them into List List<String> strings = Arrays.asList(sentence.split("\\s+")); // calling a method named countWord() as per your assignment question. Test.countWords(strings); } // implementing that method static void countWords(List<String> input){ long count = input.stream().filter(word -> word.startsWith("all") || word.startsWith("All")).count(); System.out.print("Total words starting with all/All are : "+ count +"\t"); input.stream().filter(word -> word.length() > 5).forEach( word -> System.out.print(word + "\t")); } }
  • 点击expr=Composite(AA.AuN=='ali heikal')&count=2&attributes=Ti,Y,CC,AA.AuN,AA.AuId按钮

检查实体属性文档here,了解我在评估方法文档here

后面包含的属性

我认为问题在于您使用的是具有错误端点和属性值的旧密钥。