[英]Bitbucket API Invoke-RestMethod, Powershell, Get data to Json file,webscarping
I try to do exact same thing that Bibucket API explained 我尝试做与Bibucket API解释的完全相同的事情
BitBucket says/explain BitBucket说/解释
https://confluence.atlassian.com/bitbucket/repository-resource-423626331.html https://confluence.atlassian.com/bitbucket/repository-resource-423626331.html
GET https://api.bitbucket.org/2.0/repositories/ {owner}/{repo_slug} GET https://api.bitbucket.org/2.0/repositories/ {owner} / {repo_slug}
{
"scm": "hg",
"has_wiki": true,
"description": "Site for tutorial101 files",
"links": {
"watchers": {
"href": "https://api.bitbucket.org/2.0/repositories/tutorials/tutorials.bitbucket.org/watchers"
},
"commits": {
"href": "https://api.bitbucket.org/2.0/repositories/tutorials/tutorials.bitbucket.org/commits"
},
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/tutorials/tutorials.bitbucket.org"
},
"html": {
"href": "https://bitbucket.org/tutorials/tutorials.bitbucket.org"
},
"avatar": {
"href": "https://bitbucket-assetroot.s3.amazonaws.com/c/photos/2012/Nov/28/tutorials.bitbucket.org-logo-1456883302-9_avatar.png"
},
"forks": {
"href": "https://api.bitbucket.org/2.0/repositories/tutorials/tutorials.bitbucket.org/forks"
},
"clone": [{
"href": "https://bitbucket.org/tutorials/tutorials.bitbucket.org",
"name": "https"
}, {
"href": "ssh://hg@bitbucket.org/tutorials/tutorials.bitbucket.org",
"name": "ssh"
}],
"pullrequests": {
"href": "https://api.bitbucket.org/2.0/repositories/tutorials/tutorials.bitbucket.org/pullrequests"
}
},
"fork_policy": "allow_forks",
"name": "tutorials.bitbucket.org",
"language": "html/css",
"created_on": "2011-12-20T16:35:06.480042+00:00",
"full_name": "tutorials/tutorials.bitbucket.org",
"has_issues": true,
"owner": {
"username": "tutorials",
"display_name": "tutorials account",
"uuid": "{c788b2da-b7a2-404c-9e26-d3f077557007}",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/users/tutorials"
},
"html": {
"href": "https://bitbucket.org/tutorials"
},
"avatar": {
"href": "https://bitbucket-assetroot.s3.amazonaws.com/c/photos/2013/Nov/25/tutorials-avatar-1563784409-6_avatar.png"
}
}
},
"updated_on": "2014-11-03T02:24:08.409995+00:00",
"size": 76182262,
"is_private": false,
"uuid": "{9970a9b6-2d86-413f-8555-da8e1ac0e542}"
}
I would like to do exact same thing by using powershell. 我想通过使用powershell做完全相同的事情。
So, I made a code. 因此,我编写了代码。
$username = ""
$password = ""
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
$response=Invoke-RestMethod -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Uri https://bitbucket.org/susco/azuretoquickbase -Method Get
$response
I am sure that I could log in bitbucket since I saw the content of " $responce". 我确定我可以登录bitbucket,因为我看到了“ $ responce”的内容。
then, like Bitbucket says, I added the code like this to echo out Json file . 然后,就像Bitbucket所说的,我添加了这样的代码来回显Json文件。
$username = ""
$password = ""
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
$response=Invoke-RestMethod -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Uri https://bitbucket.org/susco/azuretoquickbase -Method Get
$response
$json = $response.Content|ConvertFrom-Json
$json.data.summaries
but it is causing error 但这会导致错误
ConvertFrom-Json : Cannot bind argument to parameter 'InputObject' because it is null.
At line:11 char:27
+ $json = $response.Content|ConvertFrom-Json
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [ConvertFrom-Json], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ConvertFromJsonCommand
The point is I am sure that I could log in and get to the page bitbucket says, but it is not getting json file and null error. 关键是我确定我可以登录并进入bitbucket所说的页面,但是它没有得到json文件和null错误。
I want exactly to echo out like Bitbuckets page, How can i do that? 我想完全像Bitbuckets页面那样呼应,我该怎么做?
Invoke-RestMethod
automatically converts JSON results into objects. Invoke-RestMethod
自动将JSON结果转换为对象。 If you want just the raw result, use Invoke-WebRequest
and get the content property. 如果只需要原始结果,请使用
Invoke-WebRequest
并获取content属性。
Or in your case, since it seems you want the object, just use $json = Invoke-RestMethod ...
. 或者在您的情况下,由于似乎需要该对象,因此只需使用
$json = Invoke-RestMethod ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.