And*_*ese 14
Bitly API -获取oAuth2 访问令牌和使用缩短请求以使用Postman检索 Tiny Url 的步骤:
在花了半天的时间试图弄清楚这一点之后,我想我会发布这个,以便它可以帮助尝试与Bitly API V4集成的人。
注意: Bitly API V3 将于 2020 年 3 月 1 日停用,因此请务必尽快迁移到 V4。为了保护隐私,响应中的所有 guid 和其他私有字段都已更改。
单击此链接可参考Bitly API 文档
1.)生成访问令牌:
使用您的凭据登录 bitly.com,然后单击右上角的汉堡菜单。单击您的用户名,然后单击通用访问令牌。需要此通用访问令牌来检索您的组 Guid。您将需要此 Group Guid 来制作缩短 URL 请求以及您的访问令牌。
2.)检索组指南:
向https://api-ssl.bitly.com/v4/groups发出GET请求以获取您的 group_guid。您将在授权字段中使用您的通用访问令牌。
下面是标题的外观图片:
你应该得到一个类似于下面的 JSON 的 JSON 响应:
Retrieve Group Guid GET 响应的 JSON 响应:
{
"groups": [
{
"created": "2019-12-18T13:45:21+0000",
"modified": "2019-12-18T13:45:21+0000",
"bsds": [],
"guid": "XZXUYSJAJ43",
"organization_guid": "JsjFtE841883",
"name": "username",
"is_active": true,
"role": "org-admin",
"references": {
"organization": "https://api-ssl.bitly.com/v4/organizations/JsjFtE841883"
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
您的guid值是您在缩短和其他请求中使用的group_guid。
3.)检索您的 client_id 和 client_secret
通过使用您的用户凭据登录 bitly.com 来注册您的应用程序,您的应用程序将被分配一个 client_id 和一个 client_secret。您可以通过点击页面右侧的汉堡包菜单上做到这一点,点击您的用户名,注册OAuth的应用程序,并在底部的应该是一个按钮,上面写着注册新的APP。
4.)生成 OAuth2 访问令牌
Refer to the Bitly Documentation and under the Authentication tab navigate to "Exchanging a Username and Password for an Access Token".
• Open Postman
• Create a new POST request to https://api-ssl.bitly.com/oauth/access_token.
• Copy the Curl Command but replace username with Bitly Login Username and password with your Bitly Login Password.
• Click on the Import tab and select Past Raw Text and paste over curl command
• In the Authorization tab paste your client_id into the Username field and client_secret into the Password field. This will do the base64encoding for you.
• Your Headers only need the Host and Content-Type key and Value. Your Authorization will be be a temporary header field and will be automatically generated for you.
• Your Body needs:
grant_type: password (the actual word password)
username: your username for bitly.com
password: your password for for bitly.com
Below is a picture of what your Body should look like:
• Click Send and you will receive your access token.
5.) Shorten URL
• Open new tab in Postman and make a Post request to https://api-ssl.bitly.com/v4/shorten
• Headers should include:
• 主机:api-ssl.bitly.com
• 授权:Bearer(第 4 步中的访问令牌)
• 内容类型:应用程序/json
• 您的正文应包含此 JSON:
{
"long_url": "http://twitter.com",
"group_guid": "guid field from Group Guid Response in Step 2"
}
Run Code Online (Sandbox Code Playgroud)
• 单击发送,您应该会看到如下所示的 JSON 响应:
{
"created_at": "2019-12-18T21:50:47+0000",
"id": "yhoo/2PYRS",
"link": "http://yhoo/2PYRS",
"custom_bitlinks": [],
"long_url": "http://yahoo.com/",
"archived": false,
"tags": [],
"deeplinks": [],
"references": {
"group": "https://api-ssl.bitly.com/v4/groups/yourgroupguid"
}
}
Run Code Online (Sandbox Code Playgroud)
JSON 响应中的链接值将是您的新 Tiny URL 链接。
| 归档时间: |
|
| 查看次数: |
2175 次 |
| 最近记录: |