我一直在我的webfaction帐户上安装django社交注册.到目前为止我有facebook登录工作.当我尝试登录到Twitter时,我得到了正确的登录页面,但在选择"允许"后,我转发到以下URL:
http://example.com/social/twitter/callback/ ....其中"example.com"是转发到的实际网址.
我已经设置了twitter应用程序并输入了有效的oauth回调URL.
我在我的开发者机器上搜索了代码以获取对"example.com"的引用,但是没有找到任何代码.
任何有助于确保这一点的人都将不胜感激.
在我的User模型中,我有以下代码:
def twitter_client
OAuth::AccessToken.new(twitter_oauth, self.access_token_key, self.access_token_secret)
end
def twitter_oauth
OAuth::Consumer.new(Twitter::Login.consumer_key, Twitter::Login.secret, :site => Twitter::Login.site)
end
Run Code Online (Sandbox Code Playgroud)
这样我可以像这样调用User#twitter_client:
current_user.twitter_client.post('/statuses/update.xml', {'status' => 'foooo', 'Accept' => 'application/xml'})
Run Code Online (Sandbox Code Playgroud)
这很好用,实际上会更新状态,并返回以下内容:
#<Net::HTTPOK 200 OK readbody=true>
Run Code Online (Sandbox Code Playgroud)
这对于更新状态确实不是问题.但是,当我想获取最新的推文时,我得到的只是一个响应代码对象,没有来自响应的实际内容:
current_user.twitter_client.get('/statuses/user_timeline.xml', {'Accept' => 'application/xml'})
=> #<Net::HTTPOK 200 OK readbody=true>
Run Code Online (Sandbox Code Playgroud)
此返回的对象只是一个实例,Net::HTTPOK并且不包含推文数据.
我如何获取推文数据?
我正在与服务提供商进行通信失败:收到的身份验证质询为空
我正在尝试使用Python 3与Twitter API进行交互,以返回页面的链接,该页面为我提供了用于请求访问令牌的密码.详情如下:https://dev.twitter.com/docs/auth/pin-based-authorization
Twitter的API回复我告诉我,我没有通过返回401来正确授权我的POST请求.我最好猜测为什么我没有正确编码base64中的HMAC签名.根据我查看的正确POST请求的示例,我生成的POST请求的其他部分看起来都是正确的.
我花了几天时间研究这个问题,我希望有人可以帮我推动我完成最后一部分.
以下是Twitter API文档中最相关的部分:https://dev.twitter.com/docs/api/1/post/oauth/request_token
https://dev.twitter.com/docs/auth/authorizing-request
这是我正在使用的代码:
import urllib.parse, urllib.request, json
from hashlib import sha1
import hmac
import binascii
import time
import random
import sys
#Server Links
REQUEST_URL = "https://api.twitter.com/oauth/request_token";
ACCESS_URL = "https://api.twitter.com/oauth/access_token";
AUTHORIZE_URL = "https://api.twitter.com/oauth/authorize";
#Consumer keys
TOKEN = "Omitted"
TOKEN_SECRET = "Omitted"
#Access keys
ACCESS_TOKEN = ""
ACCESS_TOKEN_SECRET = ""
TWEET = ""
count = 1
while len(sys.argv) > count:
TWEET += sys.argv[count] + " "
count += 1
TWEET …Run Code Online (Sandbox Code Playgroud) 亚伯拉罕的twitteroauth图书馆是否适用于update_with_media?
我正在使用下面的代码,但它返回stdClass对象([request] => /1/statuses/update_with_media.json [error] =>创建状态时出错.)
session_start();
require_once('twitteroauth/twitteroauth.php');
require_once('config.php');
if (empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token']) || empty($_SESSION['access_token']['oauth_token_secret'])) {
header('Location: ./clearsessions.php');
}
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET,$_SESSION['access_token']['oauth_token'], $_SESSION['access_token']['oauth_token_secret']);
$image = './images/5298.png';
$content = $connection->post('statuses/update_with_media',
array(
'media[]' => '@{$image};type=image/jpeg;filename={$image}',
'status' => 'My current location'));
include('html.inc');
Run Code Online (Sandbox Code Playgroud)
任何人都知道如何解决这个问题?
编辑1:我使用https://upload.twitter.com/1/作为网址
我正在尝试使用Zend开发一个模块,该模块将查找我的最新推文并在我的博客上显示.
我已经阅读并了解Zend_Service_Twitter了这个课程,我想我应该从我的推特获得最新的推文.
当我启动下面给出的代码时:
public function indexAction() {
$token = unserialize('XXXXX');
$twitter = new Zend_Service_Twitter(array(
'username' => 'XXX',
'accessToken' => $token,
'consumerKey' => 'XXXX',
'consumerSecret' => 'XXXX',
'callbackUrl' => 'http://localhost/zendtest/public/blog'
));
// verify user's credentials with Twitter
$response = $twitter->account->verifyCredentials();
// Get Timeline
$response = $twitter->status->userTimeline();
$this->view->twitresponse = $response;
}
Run Code Online (Sandbox Code Playgroud)
我收到这个错误:
Fatal error:
Uncaught exception 'Zend_Service_Twitter_Exception' with message 'Twitter session is unauthorised. You need to initialize Zend_Service_Twitter with an OAuth Access Token or use its OAuth functionality to obtain …Run Code Online (Sandbox Code Playgroud) 我跑了rails generate model XXXX user_id:integer stream_url:text等
我注意到这t.timestamps是迁移文件的一部分.我可以手动删除此行而不会在将来出现任何问题吗?
我搜索过,找不到答案.我只是想在它引起问题之前提前检查.
我正在尝试按照此链接http://ckdake.com/content/2010/posting-to-twitter-from-a-ruby-on-rails-app.html中的步骤使用twitter gem
rauth中提供的示例是使用PIN而不是回调.我不明白这应该通过网络回调如何工作.
1)小问题:
根据twitter,如果oauth_callback传入了URL,则应该使用它来代替https://dev.twitter.com设置中的任何条目.然而,这似乎不是真的,如果我没有设置它,http://127.0.0.1:8080/twitter/authorized它将永远不会成功授权后到达该Url.
app.add_url_rule('/twitter/login', view_func=views.twitter_login)
app.add_url_rule('/twitter/authorized', 'twitter_authorized', view_func=views.twitter_authorized)
def twitter_login():
request_token, request_token_secret = twitter.get_request_token()
redirect_uri = url_for('twitter_authorized', _external=True)
params = {'oauth_callback': redirect_uri, 'request_token':request_token}
return redirect(twitter.get_authorize_url(**params))
Run Code Online (Sandbox Code Playgroud)
2)主要问题在于:
我可以看到request.args有['oauth_token']和['oauth_verifier'].但我不明白如何使用它们获取Twitter会话以获取用户详细信息,如图片和显示名称:
def twitter_authorized():
tw_session = twitter.get_auth_session(request_token ??? , request_token_secret ???)
resp = tw_session.get("account/verify_credentials.json", params={'format':'json'})
me = resp.json()
user = User.get_or_create(...)
if user:
login_user(user)
return redirect(url_for('index'))
Run Code Online (Sandbox Code Playgroud)
如果有人能够对此有所了解,我将非常感激.
我使用了这个Twitter librabry并得到了这个错误.谁能告诉我哪里出错了?
错误
Fatal error: Class 'Abraham\TwitterOAuth\Config' not found in D:\wamp\www\Abraham\TwitterOAuth\TwitterOAuth.php on line 17
Run Code Online (Sandbox Code Playgroud)
PHP
<?php
require_once("Abraham/TwitterOAuth/TwitterOAuth.php"); //Path to twitteroauth library you downloaded in step 3
//keys and tokens initialised
function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret) {
$connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret);
return $connection;
}
$connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);
$tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$twitteruser."&count=".$notweets);
echo json_encode($tweets);
echo $tweets; //testing remove for production
?>
Run Code Online (Sandbox Code Playgroud) 我试图用数位来自Twitter的.该AuthCallBack从活动中使用和最近时不会触发文件说,从使用AuthCallBack 应用类.
现在我让AuthCallBack正常工作并且onSuccess我需要从我的MainActivity调用一个方法.我如何从Application类实现它.请帮助.我已经给出了下面的代码.
public class MyApplication extends Application {
private AuthCallback authCallback;
@Override
public void onCreate() {
super.onCreate();
authCallback = new AuthCallback() {
@Override
public void success(DigitsSession session, String phoneNumber) {
//call myFunction() from MainActivity here
}
@Override
public void failure(DigitsException exception) {
}
};
}
public AuthCallback getAuthCallback(){
return authCallback;
}
}
Run Code Online (Sandbox Code Playgroud) android twitter-oauth twitter-digits android-application-class