Oauth2.0认证.保存access_token的问题

司徒春运 发布于 2012/03/20 21:10
阅读 2K+
收藏 2

创建了新浪微博的站内应用,使用python sdk,参照Oauth2.0的例子,写了下面代码:

CONSUMER_KEY = '**************'
CONSUMER_SECRET = '*************'
auth = APIClient(app_key=CONSUMER_KEY,app_secret=CONSUMER_SECRET,redirect_uri='http://apps.weibo.com/ddmkchan/')

def oauth(request):
    auth_url = auth.get_authorize_url()
    return HttpResponseRedirect(auth_url)

def index(request):
    code = request.GET.get('code')
    request.session['code'] = code
    if not code:
        return HttpResponseRedirect('http://ddmkchan.sinaapp.com/sinaweibo/oauth')
    else:
        r = auth.request_access_token(code)
        access_token = r.access_token
        expires_in = r.expires_in
        auth.set_access_token(access_token,expires_in)
        request.session['access_token'] = access_token
        request.session['expires_in'] = expires_in
        .....

现在的情况是:

我在自己电脑上能顺利访问应用,顺利调用新浪微博API,但是在其他机器上,使用其他微博帐号,授权并访问应用就出现access_token的问题。

access_token保存在session中。

菜鸟求指导!

加载中
0
showlove
showlove
package Tools;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

public class WeiboStore {
public static String fileName = "weibo_token_store";
	
	public static void store(Activity activity,String[] token_secret) {
		SharedPreferences settings = activity.getSharedPreferences(fileName, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = settings.edit();
		
		editor.putString("oauth_token",token_secret[0] );
		editor.putString("oauth_token_secret", token_secret[1]);	
		
		editor.commit();		
	}
	
	public static String[] fetch(Activity activity) {
		SharedPreferences settings = activity.getSharedPreferences(fileName, Context.MODE_PRIVATE);
		
		String oauth_token = settings.getString("oauth_token", null);
		String oauth_token_secret = settings.getString("oauth_token_secret", null);
		
		return new String[] {oauth_token, oauth_token_secret};
	}
	
	public static void clear(Activity activity) {
		SharedPreferences settings = activity.getSharedPreferences(fileName, Context.MODE_PRIVATE);
		
		SharedPreferences.Editor editor = settings.edit();
		
		editor.clear();  
        editor.commit(); 
	}	
}


0
雪梦科技
雪梦科技
不错,感谢分享
0
r
ruanxingzi123
不错,感谢分享
返回顶部
顶部