Skip to content

inosin/csdn-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Note: I got a lot of inspiration from this gem. Thanks simsicon.

CSDN-SDK

CSDN-SDK is a Ruby gem that provides a wrapper for interacting with CSDN API, which is currently the latest version. Check out the link if you are interested in browsing the details. The output data format is Hashie::Mash, check out here. If you are not familiar with oauth2, I recommend that you read this article.

Requirements

  1. csdn account
  2. csdn app API key
  3. csdn app API secret

Installation

$ gem install csdn-sdk

Basic Usage

The example have been moved to here.

  1. How to get the token?

    OAuth2 is simpler than its first version. In order to get the access token, you first need to get an Authorization Code through a callback request. Now use the following code to get the token.

    CsdnOAuth2::Config.api_key = YOUR_KEY
    CsdnOAuth2::Config.api_secret = YOUR_SECRET
    CsdnOAuth2::Config.redirect_uri = YOUR_CALLBACK_URL   

    If you are developing in your localhost, you can set YOUR_CALLBACK_URL as 'http://127.0.0.1/callback' something. Then set your csdn app account's callback URL as this URL too. Csdn will call the URL using GET method, which will then enable you to retrieve the authorization code.

    client = CsdnOAuth2::Client.new  

    Or you can pass the key and secret to new a client if you did not set CsdnOAuth2::Config

    Redirect to this URL. If user grants you permission, then you will get the authorization code.

    client.authorize_url

    In your callback handling method, you should add something like the following,

    client.auth_code.get_token(params[:code])

    which will give permission to your client.

  2. How to get a blog info and reply it? (or call other interfaces)

    get a blog's info and reply it

    client.blog.get_article(params[:article_id])
    client.blog.postcomment(params[:article_id], params[:content])

    Simply get a user's info.

    client.account.get_info

About

ruby sdk for csdn open salon

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages