Пример #1
0
def init():
	if not config.github_access_token:
		util.load_from_json()
	if not config.github_access_token:
		config.github_access_token = authorize(
				config.github_client_id, config.github_client_secret)
		util.save_to_json()
Пример #2
0
def init():
	if not config.facebook_access_token:
		util.load_from_json()
	if not config.facebook_access_token:
		config.facebook_access_token = authorize(
				config.facebook_app_id, config.facebook_app_secret)
		util.save_to_json()
Пример #3
0
def init():
	if not config.google_access_token or not config.google_id_token:
		util.load_from_json()
	if not config.google_access_token or not config.google_id_token:
		config.google_access_token, config.google_id_token, config.google_refresh_token \
				= authorize(config.google_client_id, config.google_client_secret)
		util.save_to_json()
Пример #4
0
def init():
    if not config.google_access_token or not config.google_id_token:
        util.load_from_json()
    if not config.google_access_token or not config.google_id_token:
        config.google_access_token, config.google_id_token, config.google_refresh_token \
          = authorize(config.google_client_id, config.google_client_secret)
        util.save_to_json()
Пример #5
0
def init(app_only=False, force=False):
	if force:
		if app_only:
			config.twitter_bearer = application_only_authentication.get_assess_token(
					config.twitter_consumer_key, config.twitter_consumer_secret)
		else:
			config.twitter_access_token, config.twitter_access_token_secret = \
					oauth.authorize(config.twitter_consumer_key, config.twitter_consumer_secret)
		util.save_to_json()

	if app_only:
		if not config.twitter_bearer:
			util.load_from_json()
		if not config.twitter_bearer:
			config.twitter_bearer = application_only_authentication.get_assess_token(
					config.twitter_consumer_key, config.twitter_consumer_secret)
			util.save_to_json()
	else:
		if not config.twitter_access_token or not config.twitter_access_token_secret:
			util.load_from_json()
		if not config.twitter_access_token or not config.twitter_access_token_secret:
			config.twitter_access_token, config.twitter_access_token_secret = \
					oauth.authorize(config.twitter_consumer_key, config.twitter_consumer_secret)
			util.save_to_json()
Пример #6
0
def init(app_only=False, force=False):
    if force:
        if app_only:
            config.twitter_bearer = application_only_authentication.get_assess_token(
                config.twitter_consumer_key, config.twitter_consumer_secret)
        else:
            config.twitter_access_token, config.twitter_access_token_secret = \
              oauth.authorize(config.twitter_consumer_key, config.twitter_consumer_secret)
        util.save_to_json()

    if app_only:
        if not config.twitter_bearer:
            util.load_from_json()
        if not config.twitter_bearer:
            config.twitter_bearer = application_only_authentication.get_assess_token(
                config.twitter_consumer_key, config.twitter_consumer_secret)
            util.save_to_json()
    else:
        if not config.twitter_access_token or not config.twitter_access_token_secret:
            util.load_from_json()
        if not config.twitter_access_token or not config.twitter_access_token_secret:
            config.twitter_access_token, config.twitter_access_token_secret = \
              oauth.authorize(config.twitter_consumer_key, config.twitter_consumer_secret)
            util.save_to_json()
Пример #7
0
parser = argparse.ArgumentParser(description=description, usage=usage,
		formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('-p', '--params', type=str, action='append', 
		help='HTTP Params, Format name=value, you can set many times')
parser.add_argument('-m', '--method', type=str, default='GET', 
		help='HTTP Method, default GET')
parser.add_argument('-c', '--clean', action='store_true',
		help='Clean access_token if it exists')
parser.add_argument('url', type=str, nargs='?', help='URL For API, like "me"')

if __name__ == '__main__':
	try:
		args = parser.parse_args()
		if args.clean:
			config.facebook_access_token = ''
			util.save_to_json()
		elif args.url:
			url = args.url
			method = args.method.upper()
			if not url.startswith('https://'):
				url = prefix + url
			params = _get_params(args.params)
			init()
			params['access_token'] = config.facebook_access_token
			if method == 'GET':
				url = url + '?' + urllib.urlencode(params)
				req = urllib2.Request(url)
			elif method == 'POST' or method == 'PUT':
				req = urllib2.Request(url)
				req.data = urllib.urlencode(params)
				req.add_header('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8')