简体   繁体   中英

Access Bitbucket from java code & read files

Wanted to access files there in Bitbucket from java code. Is there any way to access bitbucket from code.

Yes, there is, checkout the documentation link , Bellow just a preview

You can list files

https://api.bitbucket.org/1.0/repositories/{accountname}/{repo_slug}/src/{revision}/{path}

Or get a file raw content

https://api.bitbucket.org/1.0/repositories/{accountname}/{repo_slug}/raw/{revision}/{path}

Update - 2018-01-04

Based in this article you can use Basic Authentication or oAuth (recommended by Atlassian), as the Basic Authentication is more simple to do then here a full Basic Authentication sample:

$ curl -i https://ElvisDeFreitas:myVerySecretPassword@api.bitbucket.org/1.0/repositories/ElvisDeFreitas/jna-examples/src/4bd1a0f584af/src/main/java/nativeapi/jna/syscall
HTTP/1.1 200 OK
Server: nginx
Vary: Authorization
Content-Type: application/json; charset=utf-8
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
Date: Thu, 04 Jan 2018 09:38:27 GMT
X-Served-By: app-142
ETag: "3414c377599e4dc02df7b370ffc557b5"
X-Static-Version: 2cd31fe906e9
X-Content-Type-Options: nosniff
X-Accepted-OAuth-Scopes: repository
X-Credential-Type: password
X-Render-Time: 0.156632900238
Connection: keep-alive
X-Request-Count: 300
X-Version: 2cd31fe906e9
X-Frame-Options: SAMEORIGIN
Content-Length: 668
{
    "node": "4bd1a0f584af",
    "path": "src/main/java/nativeapi/jna/syscall/",
    "directories": [],
    "files": [
        {
            "size": 19248,
            "path": "src/main/java/nativeapi/jna/syscall/BytesUtils.java",
            "timestamp": "2016-10-18T19:09:06Z",
            "utctimestamp": "2016-10-18 19:09:06+00:00",
            "revision": "4bd1a0f584af"
        },
        {
            "size": 723,
            "path": "src/main/java/nativeapi/jna/syscall/HelloWorldJNA.java",
            "timestamp": "2016-10-17T19:45:10Z",
            "utctimestamp": "2016-10-17 19:45:10+00:00",
            "revision": "40cd9622d67c"
        },
        {
            "size": 611,
            "path": "src/main/java/nativeapi/jna/syscall/TestJNA.java",
            "timestamp": "2016-10-17T19:45:10Z",
            "utctimestamp": "2016-10-17 19:45:10+00:00",
            "revision": "40cd9622d67c"
        }
    ]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM