我尝试使用Go编写的this论坛软件,其中包含一个配置文件,该文件需要您在main.go中看到的值。我尝试使用空字符串""
来在我的本地计算机上播放oauth凭据,但是我收到了错误
json. json: cannot unmarshal string into Go value of type oauth.Credentials
所以,即使我将它部署在服务器上,我还是认为我必须将字符串作为字符串输入,这也会触发错误。
假设我的api密钥和秘密是这样的
key= X482xYAFG1I2RKBYR
secret = 4929390593pqI4wNMljlj4N71oyOdlWCzyNKhv4BAd4QXLvW2LF
考虑到以下main.go
的要求,您将如何在config.json文件中输入凭据
{
"TwitterOAuthCredentials":,
"CookieAuthKeyHexStr":"2ded82bb63514dbd6a0af42a25df235c",
"CookieEncrKeyHexStr":"4add93d1d6bb3489c9b3ab5448704068",
"AnalyticsCode":"",
"AwsAccess":"",
"AwsSecret":"",
"S3BackupBucket":"",
"S3BackupDir": ""
}
main.go
中的配置要求config = struct {
TwitterOAuthCredentials *oauth.Credentials
CookieAuthKeyHexStr *string
CookieEncrKeyHexStr *string
AnalyticsCode *string
AwsAccess *string
AwsSecret *string
S3BackupBucket *string
S3BackupDir *string
}{
&oauthClient.Credentials,
nil, nil,
nil,
nil, nil,
nil, nil,
}
答案 0 :(得分:1)
如果您不想设置它,请完全将其保留,并将其设置为默认值。
否则,输入oauth.Credentials
的json表示,该表示只是Token
和Secret
字符串:
type Credentials struct {
Token string // Also known as consumer key or access token.
Secret string // Also known as consumer secret or access token secret.
}
在您的配置中,凭据如下所示:
"TwitterOAuthCredentials": {
"Token": "oauthtoken",
"Secret": "oauthsecret"
},