Coder Social home page Coder Social logo

oauth_china's Introduction

unmaintained

简介

  • 通过OAuth方式同步用户消息到微博平台(支持豆瓣,新浪微薄,腾讯微博,搜狐微博,网易微博)
  • 和omini-auth的区别:omini-auth是专门提供oauth授权和获取用户信息的gem(比如用新浪微博帐号登陆这种需求)
  • oauth_china是一个方便的同步信息到其他微博平台的gem(用来做像follow5.com或http://fanfou.com/settings/sync这样需求)

安装

gem install oauth_china

使用

  • 在Gemfile里添加:
gem 'oauth'
gem 'oauth_china'
  • 添加配置文件
config/oauth/douban.yml
config/oauth/sina.yml
config/oauth/qq.yml
config/oauth/sohu.yml
config/oauth/netease.yml
  • 配置文件格式:
development:
      key:    "you api key"
      secret: "your secret"
      url:    "http://yoursite.com"
      callback: "http://localhost:3000/your_callback_url"
production:
      key:    "you api key"
      secret: "your secret"
      url:    "http://yoursite.com"
      callback: "http://localhost:3000/your_callback_url"
  • 演示
#config/routes.rb
match "syncs/:type/new" => "syncs#new", :as => :sync_new
match "syncs/:type/callback" => "syncs#callback", :as => :sync_callback

# encoding: UTF-8
class SyncsController < ApplicationController

  def new
    client = OauthChina::Sina.new
    authorize_url = client.authorize_url
    Rails.cache.write(build_oauth_token_key(client.name, client.oauth_token), client.dump)
    redirect_to authorize_url
  end

  def callback
    client = OauthChina::Sina.load(Rails.cache.read(build_oauth_token_key(params[:type], params[:oauth_token])))
    client.authorize(:oauth_verifier => params[:oauth_verifier])

    results = client.dump

    if results[:access_token] && results[:access_token_secret]
      #在这里把access token and access token secret存到db
      #下次使用的时候:
      #client = OauthChina::Sina.load(:access_token => "xx", :access_token_secret => "xxx")
      #client.add_status("同步到新浪微薄..")
      flash[:notice] = "授权成功!"
    else
      flash[:notice] = "授权失败!"
    end
    redirect_to root_path
  end

  private
  def build_oauth_token_key(name, oauth_token)
    [name, oauth_token].join("_")
  end
end
  • 注意

系统时间要正确设置。否则会出现timstamps refused错误

API文档

License

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

You should have read the GNU General Public License before start "RTFSC".

If not, see http://www.gnu.org/licenses/


By db-china.org

oauth_china's People

Contributors

bryant1410 avatar centaur avatar hooopo avatar juanitofatas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

oauth_china's Issues

兼容性

这。。就是给 rails 用的吧 ==

QQ微博check sign error的问题

在用 client.get的时候,经常发现如果并发或者请求间隔太短,会出现check sign error的情况。

如用循环,获取每个听众的详细资料。大概在第三、第四个请求的时候就会出现这个错误。我用捕捉异常之后用retry,重试两三次之后可以获得正常数据。

第一次请求
http://open.t.qq.com/api/user/other_info?format=json&name=Yilian_1224
返回
{"data":null,"errcode":-111,"msg":"check sign error","ret":3}
retry
http://open.t.qq.com/api/user/other_info?format=json&name=Yilian_1224
返回
{"data":{"Ismyblack":0,"Ismyfans":1,"Ismyidol":1,"birth_day":0,"birth_month":0,"birth_year":0……

搜索了一下,目前有一说是要把 oauth_signature 裏的 + 替換為為 %2B 原文地址:http://fjthk.now.cn:7751/open.t.qq.com/bbs/forum.php?mod=viewthread&tid=8452

不知道是不是这个原因?

params[:type] is blank

在示例代码中,callback里面传回的参数没有params[:type],这里应该是client.name

这个gem里面貌似只有授权登录几个最基本的api,其他的貌似都还没有实现,hooopo兄要不找几个兄弟一起完善下。

使用过程中遇到的问题

刚刚使用时遇到两个问题,,,

1)Sohu微博出现以下问题:

NoMethodError in MemberController#syncs_new

undefined method `gsub' for nil:NilClass

activesupport (3.1.1) lib/active_support/whiny_nil.rb:48:in method_missing' /opt/ruby/lib/ruby/1.9.1/cgi/util.rb:7:inescape'
oauth (0.4.5) lib/oauth/tokens/request_token.rb:28:in block in build_authorize_url' oauth (0.4.5) lib/oauth/tokens/request_token.rb:28:ineach'
oauth (0.4.5) lib/oauth/tokens/request_token.rb:28:in map' oauth (0.4.5) lib/oauth/tokens/request_token.rb:28:inbuild_authorize_url'
oauth (0.4.5) lib/oauth/tokens/request_token.rb:9:in authorize_url' oauth_china (0.4.0) lib/oauth_china.rb:72:inauthorize_url'

2)网易微博出下以下问题:

OAuth::Problem in MemberController#syncs_new

consumer not found

oauth (0.4.5) lib/oauth/consumer.rb:181:in request' oauth (0.4.5) lib/oauth/consumer.rb:197:intoken_request'
oauth (0.4.5) lib/oauth/consumer.rb:139:in get_request_token' oauth_china (0.4.0) lib/oauth_china.rb:28:ininitialize'
oauth_china (0.4.0) lib/oauth_china/strategies/netease.rb:14:in `initialize'

请问如何解决,谢谢!

关于腾讯微薄授权完成后不能回调的问题

Hi, 最近在做腾讯微薄OAuth授权, 遇到了一个小问题:

获取request token的时候会去到:
https://open.t.qq.com/cgi-bin/authorize?oauth_token=cddcb75b0f544f0d8a6b4d1e9527a54f&oauth_callback=http://ws.yyfx.net/oauth/tqq_callback?account_id=&oauth_token_secret=0f005390d69eb8288b303ab37b68af7e

之后会重定向到:
http://open.t.qq.com/oauth_html/login.php?oauth_token=cddcb75b0f544f0d8a6b4d1e9527a54f&type=0

当点击授权后,却没有调用callback url

不知道有没碰到这种情况 ? 谢谢

client.add_status出个奇怪的错 "delegated to access_token.post"

client = OauthChina::Sina.load(:access_token => access_token,:token_secret => token_secret)
client.add_status('I am speechless.........')

RuntimeError (OauthChina::OAuth#post delegated to access_token.post, but access_token is nil: #<OauthChina::Sina:0x007fbcdfa0ec88 @consumer_options={:site=>"http://api.t.sina.com.cn", :request_token_path=>"/oauth/request_token", :access_token_path=>"/oauth/access_token", :authorize_path=>"/oauth/authorize", :realm=>"http:/www.com"}, @consumer=#<OAuth::Consumer:0x007fbcdfa0e8a0

微博发图片:status值中文错误

status 为中文是有点小错误,看了一下 插件 应该是没有转码,

所以我在upload_image(URI.escape("中文"),image_tag) 可以解决问题

希望能内置中文 支持伟大的** 呵呵!

qq微薄api上传图片的问题

我把gem的代码upload_image注释去了,在搞的时候出现:
{"data"=>nil, "errcode"=>9, "msg"=>"check sign error", "ret"=>3}
这个貌似是因为图片不参与签名的问题还是什么?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.