尝试使用Golang编写的Microsoft Graph API时出现类型错误。

huangapple go评论84阅读模式
英文:

Type error trying the microsoft graph api for golang

问题

我目前正在尝试使用微软图形 API 的 Golang 示例。在使用其中一个示例时,我遇到了以下错误:

"Cannot use '&contentType' (type *string) as the type *BodyType"

在其他示例中,我会理解这只是错误的类型,而不是传递了一个 *string 类型,而是需要传递一个字符串类型。但是在这种情况下,我不知道 *BodyType 是什么?他们在这里寻找什么?

我也遇到了相同的错误,用于 inferenceClassification:

Cannot use '&inferenceClassification' (type *string) as the type *InferenceClassificationType

我对这是什么寻找也没有头绪。

对于这些基础问题,我表示抱歉。

更新:
根据 Gavin 的评论,它期望一个整数
contentType := 1
body.SetContentType((*msgraphsdk.BodyType)(&contentType))

英文:

I am currently playing around with the microsoft graph api examples for golang.

I am getting the following error using one of their examples:

"Cannot use '&contentType' (type *string) as the type *BodyType"

In other examples I would understand that its simply the wrong type and instead of passing in a type *string I need to pass in e.g a string.

However I have no idea what a *BodyType is in this scenario? What are they looking for here?
https://learn.microsoft.com/en-gb/graph/api/message-update?view=graph-rest-1.0&tabs=go

requestBody := msgraphsdkm.NewMessage()
subject := "subject-value"
requestBody.SetSubject(&subject)
body := msgraphsdkm.NewItemBody()
requestBody.SetBody(body)
contentType := ""
body.SetContentType(&contentType)
content := "content-value"
body.SetContent(&content)
inferenceClassification := "other"
requestBody.SetInferenceClassification(&inferenceClassification)
messageId := "message-id"
graphClient.Me().MessagesById(&messageId).Patch(requestBody)

I am also getting the same error for inferenceClassification

Cannot use '&inferenceClassification' (type *string) as the type *InferenceClassificationType
I've also no idea what this is looking for?

Apologies for the basic questions

Update:
As per Gavins comment its expecting an int
contentType := 1
body.SetContentType((*msgraphsdk.BodyType)(&contentType))

答案1

得分: 0

以下是要翻译的内容:

contentType := 1

body.SetContentType((*msgraphsdkm.BodyType)(&contentType))

根据Gavin的评论,它需要一个整数。
https://github.com/microsoftgraph/msgraph-sdk-go/blob/eb2d097f9010a618832461f649740084d7823b02/models/body_type.go#L6

英文:
contentType := 1

body.SetContentType((*msgraphsdkm.BodyType)(&contentType))

It needed an int as per Gavins comment
https://github.com/microsoftgraph/msgraph-sdk-go/blob/eb2d097f9010a618832461f649740084d7823b02/models/body_type.go#L6

huangapple
  • 本文由 发表于 2022年7月6日 23:26:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/72886213.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定