Commit 44beb0bc authored by Daniel Kreuter's avatar Daniel Kreuter
Browse files

Changed API version from Twitter from 1.0 to 1.1

Changed API version from 1.0 to 1.1 because 1.0 has been shut down.

Also applied both patches from Mario Bensi regarding twitter search
and direct_messages.

BUG: 264091
parent b8091211
......@@ -83,9 +83,9 @@ TwitterApiMicroBlog::TwitterApiMicroBlog ( const KComponentData &instance, QObje
{
kDebug();
KConfigGroup grp(KGlobal::config(), "TwitterApi");
format = grp.readEntry("format", "xml");
format = grp.readEntry("format", "json");
setCharLimit(140);
setCharLimit(140); //TODO: See if we can ask twitter for the char limit and make it dynamic
QStringList timelineTypes;
timelineTypes<< "Home" << "Reply" << "Inbox" << "Outbox" << "Favorite" << "ReTweets" << "Public";
setTimelineNames(timelineTypes);
......@@ -404,19 +404,12 @@ void TwitterApiMicroBlog::slotCreatePost ( KJob *job )
} else {
KIO::StoredTransferJob *stj = qobject_cast< KIO::StoredTransferJob * > ( job );
if ( !post->isPrivate ) {
if(format=="xml"){
readPostFromXml ( theAccount, stj->data(), post );
} else {
readPostFromJson ( theAccount, stj->data(), post );
}
if ( post->isError ) {
QString errorMsg;
if(format == "json")
errorMsg = checkJsonForError(stj->data());
else
errorMsg = checkXmlForError(stj->data());
if( errorMsg.isEmpty() ){
kError() << "Creating post: XML parsing error: "<< stj->data() ;
readPostFromJson ( theAccount, stj->data(), post );
if ( post->isError ) {
QString errorMsg;
errorMsg = checkJsonForError(stj->data());
if( errorMsg.isEmpty() ){ // ???? If empty, why is there an error?
kError() << "Creating post: JSON parsing error: "<< stj->data() ;
emit errorPost ( theAccount, post, Choqok::MicroBlog::ParsingError,
i18n ( "Creating the new post failed. The result data could not be parsed." ), MicroBlog::Critical );
} else {
......@@ -497,17 +490,10 @@ void TwitterApiMicroBlog::slotFetchPost ( KJob *job )
i18n("Fetching the new post failed. %1", job->errorString()), Low );
} else {
KIO::StoredTransferJob *stj = qobject_cast<KIO::StoredTransferJob *> ( job );
if(format=="json"){
readPostFromJson ( theAccount, stj->data(), post );
} else {
readPostFromXml ( theAccount, stj->data(), post );
}
readPostFromJson ( theAccount, stj->data(), post );
if ( post->isError ) {
QString errorMsg;
if(format == "json")
errorMsg = checkJsonForError(stj->data());
else
errorMsg = checkXmlForError(stj->data());
errorMsg = checkJsonForError(stj->data());
if( errorMsg.isEmpty() ){
kDebug() << "Parsing Error";
emit errorPost ( theAccount, post, Choqok::MicroBlog::ParsingError,
......@@ -522,7 +508,6 @@ void TwitterApiMicroBlog::slotFetchPost ( KJob *job )
} else {
post->isError = true;
emit postFetched ( theAccount, post );
// mFetchPostMap.remove(job);
}
}
}
......@@ -534,9 +519,9 @@ void TwitterApiMicroBlog::removePost ( Choqok::Account* theAccount, Choqok::Post
TwitterApiAccount* account = qobject_cast<TwitterApiAccount*>(theAccount);
KUrl url = account->apiUrl();
if ( !post->isPrivate ) {
url.addPath ( "/statuses/destroy/" + post->postId + ".xml" );
url.addPath ( "/statuses/destroy/" + post->postId + ".json" );
} else {
url.addPath ( "/direct_messages/destroy/" + post->postId + ".xml" );
url.addPath ( "/direct_messages/destroy/" + post->postId + ".json" );
}
KIO::StoredTransferJob *job = KIO::storedHttpPost ( QByteArray(), url, KIO::HideProgressInfo ) ;
if ( !job ) {
......@@ -568,7 +553,7 @@ void TwitterApiMicroBlog::slotRemovePost ( KJob *job )
i18n("Removing the post failed. %1", job->errorString() ), MicroBlog::Critical );
} else {
KIO::StoredTransferJob *stj = qobject_cast<KIO::StoredTransferJob*>(job);
QString errMsg = checkXmlForError(stj->data());
QString errMsg = checkJsonForError(stj->data());
if( errMsg.isEmpty() ){
emit postRemoved ( theAccount, post );
} else {
......@@ -614,7 +599,7 @@ void TwitterApiMicroBlog::slotCreateFavorite ( KJob *job )
emit error ( theAccount, CommunicationError, i18n( "Favorite creation failed. %1", job->errorString() ) );
} else {
KIO::StoredTransferJob* stJob = qobject_cast<KIO::StoredTransferJob*>( job );
QString err = checkXmlForError(stJob->data());
QString err = checkJsonForError(stJob->data());
if( !err.isEmpty() ){
emit error(theAccount, ServerError, err, Critical);
return;
......@@ -659,7 +644,7 @@ void TwitterApiMicroBlog::slotRemoveFavorite ( KJob *job )
emit error ( theAccount, CommunicationError, i18n("Removing the favorite failed. %1", job->errorString() ) );
} else {
KIO::StoredTransferJob* stJob = qobject_cast<KIO::StoredTransferJob*>( job );
QString err = checkXmlForError(stJob->data());
QString err = checkJsonForError(stJob->data());
if( !err.isEmpty() ){
emit error(theAccount, ServerError, err, Critical);
return;
......@@ -712,7 +697,7 @@ void TwitterApiMicroBlog::slotRequestFriendsScreenName(KJob* job)
return;
}
QStringList newList;
newList = readUsersScreenNameFromXml( theAccount, stJob->data() );
newList = readUsersScreenNameFromJson( theAccount, stJob->data() );
friendsList << newList;
if ( newList.count() == 100 ) {
requestFriendsScreenName( theAccount );
......@@ -744,7 +729,7 @@ void TwitterApiMicroBlog::requestTimeLine ( Choqok::Account* theAccount, QString
int countOfPost = Choqok::BehaviorSettings::countOfPosts();
QOAuth::ParamMap params;
if( account->usingOAuth() ){
if( account->usingOAuth() ){ //TODO: Check if needed
if ( !latestStatusId.isEmpty() ) {
params.insert ( "since_id", latestStatusId.toLatin1() );
countOfPost = 200;
......@@ -803,17 +788,10 @@ void TwitterApiMicroBlog::slotRequestTimeline ( KJob *job )
KIO::StoredTransferJob* j = qobject_cast<KIO::StoredTransferJob*>( job );
QList<Choqok::Post*> list;
if( type=="Inbox" || type=="Outbox" ) {
if(format=="json"){
list = readDMessagesFromJson( theAccount, j->data() );
} else {
list = readDMessagesFromXml( theAccount, j->data() );
}
list = readDMessagesFromJson( theAccount, j->data() );
} else {
if(format=="json"){
list = readTimelineFromJson( theAccount, j->data() );
} else {
list = readTimelineFromXml( theAccount, j->data() );
}
list = readTimelineFromJson( theAccount, j->data() );
}
if(!list.isEmpty()) {
mTimelineLatestId[theAccount][type] = list.last()->postId;
......@@ -837,7 +815,7 @@ QByteArray TwitterApiMicroBlog::authorizationHeader(TwitterApiAccount* theAccoun
return auth;
}
Choqok::Post * TwitterApiMicroBlog::readPostFromXml ( Choqok::Account* theAccount,
/*Choqok::Post * TwitterApiMicroBlog::readPostFromXml ( Choqok::Account* theAccount,
const QByteArray& buffer, Choqok::Post* post )
{
QDomDocument document;
......@@ -857,9 +835,9 @@ Choqok::Post * TwitterApiMicroBlog::readPostFromXml ( Choqok::Account* theAccoun
post->isError = true;
return post;
}
}
}*/
Choqok::Post * TwitterApiMicroBlog::readPostFromDomElement ( Choqok::Account* theAccount,
/*Choqok::Post * TwitterApiMicroBlog::readPostFromDomElement ( Choqok::Account* theAccount,
const QDomElement &root, Choqok::Post* post )
{
if(!post){
......@@ -876,9 +854,9 @@ Choqok::Post * TwitterApiMicroBlog::readPostFromDomElement ( Choqok::Account* th
QDomNode node2 = root.firstChild();
return readPostFromDomNode(theAccount, node2, post);;
}
}*/
Choqok::Post* TwitterApiMicroBlog::readPostFromDomNode(Choqok::Account* theAccount,
/*Choqok::Post* TwitterApiMicroBlog::readPostFromDomNode(Choqok::Account* theAccount,
QDomNode node, Choqok::Post* post)
{
Choqok::Post* repeatedPost = 0;
......@@ -935,9 +913,9 @@ Choqok::Post* TwitterApiMicroBlog::readPostFromDomNode(Choqok::Account* theAccou
post->link = postUrl(theAccount, post->author.userName, post->postId);
post->isRead = post->isFavorited || (post->repeatedFromUsername.compare(theAccount->username(), Qt::CaseInsensitive) == 0);
return post;
}
}*/
QList<Choqok::Post*> TwitterApiMicroBlog::readTimelineFromXml ( Choqok::Account* theAccount,
/*QList<Choqok::Post*> TwitterApiMicroBlog::readTimelineFromXml ( Choqok::Account* theAccount,
const QByteArray &buffer )
{
QDomDocument document;
......@@ -959,9 +937,9 @@ QList<Choqok::Post*> TwitterApiMicroBlog::readTimelineFromXml ( Choqok::Account*
node = node.nextSibling();
}
return postList;
}
}*/
Choqok::Post * TwitterApiMicroBlog::readDMessageFromXml (Choqok::Account *theAccount, const QByteArray &buffer )
/*Choqok::Post * TwitterApiMicroBlog::readDMessageFromXml (Choqok::Account *theAccount, const QByteArray &buffer )
{
QDomDocument document;
document.setContent ( buffer );
......@@ -977,9 +955,9 @@ Choqok::Post * TwitterApiMicroBlog::readDMessageFromXml (Choqok::Account *theAcc
Q_EMIT error(theAccount, ServerError, err);
return post;
}
}
}*/
Choqok::Post * TwitterApiMicroBlog::readDMessageFromDomElement ( Choqok::Account* theAccount,
/*Choqok::Post * TwitterApiMicroBlog::readDMessageFromDomElement ( Choqok::Account* theAccount,
const QDomElement& root )
{
Choqok::Post *msg = new Choqok::Post;
......@@ -1060,9 +1038,9 @@ Choqok::Post * TwitterApiMicroBlog::readDMessageFromDomElement ( Choqok::Account
msg->replyToUserName = recipientScreenName;
}
return msg;
}
}*/
QList<Choqok::Post*> TwitterApiMicroBlog::readDMessagesFromXml (Choqok::Account *theAccount,
/*QList<Choqok::Post*> TwitterApiMicroBlog::readDMessagesFromXml (Choqok::Account *theAccount,
const QByteArray &buffer )
{
QDomDocument document;
......@@ -1084,9 +1062,9 @@ QList<Choqok::Post*> TwitterApiMicroBlog::readDMessagesFromXml (Choqok::Account
node = node.nextSibling();
}
return postList;
}
}*/
QStringList TwitterApiMicroBlog::readUsersScreenNameFromXml( Choqok::Account* theAccount, const QByteArray& buffer )
/*QStringList TwitterApiMicroBlog::readUsersScreenNameFromXml( Choqok::Account* theAccount, const QByteArray& buffer )
{
kDebug();
QStringList list;
......@@ -1131,7 +1109,7 @@ QStringList TwitterApiMicroBlog::readUsersScreenNameFromXml( Choqok::Account* th
section = section.nextSibling();
}
return list;
}
}*/
void TwitterApiMicroBlog::setRepeatedOfInfo(Choqok::Post* post, Choqok::Post* repeatedPost)
{
......@@ -1171,7 +1149,6 @@ void TwitterApiMicroBlog::aboutToUnload()
d->countOfTimelinesToSave = 0;
foreach(Choqok::Account* acc, Choqok::AccountManager::self()->accounts()){
if(acc->microblog() == this){
// acc->writeConfig();
d->countOfTimelinesToSave += acc->timelineNames().count();
}
}
......@@ -1257,14 +1234,14 @@ void TwitterApiMicroBlog::slotCreateFriendship(KJob* job)
return;
}
KIO::StoredTransferJob *stj = qobject_cast<KIO::StoredTransferJob*>(job);
Choqok::User *user = readUserInfoFromXml(stj->data());
Choqok::User *user = readUserInfoFromJson(stj->data());
if( user /*&& user->userName.compare(username, Qt::CaseInsensitive)*/ ){
emit friendshipCreated(theAccount, username);
Choqok::NotifyManager::success( i18n("You are now listening to %1's posts.", username) );
theAccount->setFriendsList(QStringList());
listFriendsUsername(theAccount);
} else {
QString errorMsg = checkXmlForError(stj->data());
QString errorMsg = checkJsonForError(stj->data());
if( errorMsg.isEmpty() ){
kDebug()<<"Parse Error: "<<stj->data();
emit error( theAccount, ParsingError,
......@@ -1315,14 +1292,14 @@ void TwitterApiMicroBlog::slotDestroyFriendship(KJob* job)
return;
}
KIO::StoredTransferJob *stj = qobject_cast<KIO::StoredTransferJob*>(job);
Choqok::User *user = readUserInfoFromXml(stj->data());
Choqok::User *user = readUserInfoFromJson(stj->data());
if( user /*&& user->userName.compare( username, Qt::CaseInsensitive )*/ ){
emit friendshipDestroyed(theAccount, username);
Choqok::NotifyManager::success( i18n("You will not receive %1's updates.", username) );
theAccount->setFriendsList(QStringList());
listFriendsUsername(theAccount);
} else {
QString errorMsg = checkXmlForError(stj->data());
QString errorMsg = checkJsonForError(stj->data());
if( errorMsg.isEmpty() ){
kDebug()<<"Parse Error: "<<stj->data();
emit error( theAccount, ParsingError,
......@@ -1371,7 +1348,7 @@ void TwitterApiMicroBlog::slotBlockUser(KJob* job)
i18n("Blocking %1 failed. %2", username, job->errorString() ) );
return;
}
Choqok::User *user = readUserInfoFromXml(qobject_cast<KIO::StoredTransferJob*>(job)->data());
Choqok::User *user = readUserInfoFromJson(qobject_cast<KIO::StoredTransferJob*>(job)->data());
if( user /*&& user->userName.compare( username, Qt::CaseInsensitive )*/ ){
emit userBlocked(theAccount, username);
Choqok::NotifyManager::success( i18n("You will no longer be disturbed by %1.", username) );
......@@ -1381,10 +1358,10 @@ void TwitterApiMicroBlog::slotBlockUser(KJob* job)
i18n("Blocking %1 failed: the server returned invalid data.",
username ) );
}
// Choqok::User *user = readUserInfoFromXml(); TODO Check for failor!
//TODO Check for failor!
}
Choqok::User* TwitterApiMicroBlog::readUserInfoFromXml(const QByteArray& buffer)
/*Choqok::User* TwitterApiMicroBlog::readUserInfoFromXml(const QByteArray& buffer)
{
QDomDocument doc;
doc.setContent(buffer);
......@@ -1421,9 +1398,9 @@ Choqok::User* TwitterApiMicroBlog::readUserInfoFromXml(const QByteArray& buffer)
node = node.nextSibling();
}
return user;
}
}*/
QString TwitterApiMicroBlog::checkXmlForError(const QByteArray& buffer)
/*QString TwitterApiMicroBlog::checkXmlForError(const QByteArray& buffer)
{
QDomDocument doc;
doc.setContent(buffer);
......@@ -1446,7 +1423,7 @@ QString TwitterApiMicroBlog::checkXmlForError(const QByteArray& buffer)
} else {
return QString();
}
}
}*/
///===================================================================
......@@ -1503,7 +1480,7 @@ Choqok::Post* TwitterApiMicroBlog::readPostFromJson(Choqok::Account* theAccount,
return readPostFromJsonMap ( theAccount, map, post );
} else {
if(!post){
kError()<<"TwitterApiMicroBlog::readPostFromXml: post is NULL!";
kError()<<"TwitterApiMicroBlog::readPostFromJson: post is NULL!";
post = new Choqok::Post;
}
emit errorPost(theAccount, post, ParsingError, i18n("Could not parse the data that has been received from the server."));
......
......@@ -212,22 +212,22 @@ protected:
///==============================================
/// XML:
///==============================================
virtual Choqok::Post * readPostFromDomElement( Choqok::Account* theAccount,
const QDomElement& root, Choqok::Post* post );
virtual Choqok::Post *readPostFromDomNode(Choqok::Account* theAccount,
QDomNode node, Choqok::Post* post);
virtual Choqok::Post * readPostFromXml( Choqok::Account* theAccount,
const QByteArray& buffer, Choqok::Post* post );
virtual QList<Choqok::Post*> readTimelineFromXml( Choqok::Account* theAccount, const QByteArray& buffer );
virtual Choqok::Post * readDMessageFromXml (Choqok::Account *theAccount, const QByteArray &buffer );
virtual Choqok::Post * readDMessageFromDomElement (Choqok::Account *theAccount, const QDomElement& root );
virtual QList<Choqok::Post*> readDMessagesFromXml (Choqok::Account *theAccount, const QByteArray &buffer );
virtual QStringList readUsersScreenNameFromXml( Choqok::Account *theAccount, const QByteArray & buffer );
virtual Choqok::User *readUserInfoFromXml( const QByteArray &buffer );
//virtual Choqok::Post * readPostFromDomElement( Choqok::Account* theAccount,
// const QDomElement& root, Choqok::Post* post );
//virtual Choqok::Post *readPostFromDomNode(Choqok::Account* theAccount,
// QDomNode node, Choqok::Post* post);
//virtual Choqok::Post * readPostFromXml( Choqok::Account* theAccount,
// const QByteArray& buffer, Choqok::Post* post );
//virtual QList<Choqok::Post*> readTimelineFromXml( Choqok::Account* theAccount, const QByteArray& buffer );
//virtual Choqok::Post * readDMessageFromXml (Choqok::Account *theAccount, const QByteArray &buffer );
//virtual Choqok::Post * readDMessageFromDomElement (Choqok::Account *theAccount, const QDomElement& root );
//virtual QList<Choqok::Post*> readDMessagesFromXml (Choqok::Account *theAccount, const QByteArray &buffer );
//virtual QStringList readUsersScreenNameFromXml( Choqok::Account *theAccount, const QByteArray & buffer );
//virtual Choqok::User *readUserInfoFromXml( const QByteArray &buffer );
/**
Checks xml returned from server for error, and return error string, Or an empty string if nothing found!
*/
virtual QString checkXmlForError(const QByteArray &buffer);
//virtual QString checkXmlForError(const QByteArray &buffer);
///===============================================
/// JSON:
......@@ -246,7 +246,7 @@ protected:
virtual Choqok::User *readUserInfoFromJson( const QByteArray &buffer );
virtual Choqok::User readUserFromJsonMap( Choqok::Account* theAccount, const QVariantMap& map );
/**
Checks xml returned from server for error, and return error string, Or an empty string if nothing found!
Checks json returned from server for error, and return error string, Or an empty string if nothing found!
*/
virtual QString checkJsonForError(const QByteArray &buffer);
///=================================================
......
/*
This file is part of Choqok, the KDE micro-blogging client
Copyright (C) 2008-2012 Mehrdad Momeny <mehrdad.momeny@gmail.com>
......@@ -23,10 +23,27 @@
*/
#include "twitterapisearch.h"
#include <stdio.h>
class TwitterApiSearch::Private
{
public:
Private()
{
monthes["Jan"] = 1;
monthes["Feb"] = 2;
monthes["Mar"] = 3;
monthes["Apr"] = 4;
monthes["May"] = 5;
monthes["Jun"] = 6;
monthes["Jul"] = 7;
monthes["Aug"] = 8;
monthes["Sep"] = 9;
monthes["Oct"] = 10;
monthes["Nov"] = 11;
monthes["Dec"] = 12;
}
QMap<QString, int> monthes;
};
TwitterApiSearch::TwitterApiSearch(QObject* parent)
......@@ -54,6 +71,18 @@ void TwitterApiSearch::requestSearchResults(Choqok::Account* theAccount, const Q
requestSearchResults(info, sinceStatusId, count, page);
}
QDateTime TwitterApiSearch::dateFromString ( const QString &date )
{
char s[10];
int year, day, hours, minutes, seconds, tz;
sscanf( qPrintable ( date ), "%*s %s %d %d:%d:%d %d %d", s, &day, &hours, &minutes, &seconds, &tz, &year );
int month = d->monthes[s];
QDateTime recognized ( QDate ( year, month, day ), QTime ( hours, minutes, seconds ) );
if(tz == 0)//tz is the timezone, in Twitter it's always UTC(0) in Identica it's local +/-NUMBER
recognized.setTimeSpec( Qt::UTC );
return recognized.toLocalTime();
}
SearchInfo::SearchInfo()
{
......@@ -80,4 +109,4 @@ bool SearchInfo::fromString(const QString& str)
QString SearchInfo::toString()
{
return account->alias() + ",,," + QString::number(option) + ",,," + query + ",,," + QString::number(isBrowsable);
}
}
\ No newline at end of file
......@@ -94,6 +94,8 @@ public:
*/
virtual QString optionCode(int option) = 0;
QDateTime dateFromString( const QString &date );
public Q_SLOTS:
virtual void requestSearchResults( const SearchInfo &searchInfo,
const ChoqokId &sinceStatusId = QString(),
......
......@@ -267,11 +267,11 @@ void LaconicaMicroBlog::slotRequestFriendsScreenName(KJob* job)
TwitterApiAccount *theAccount = qobject_cast<TwitterApiAccount *>( mJobsAccount.take(job) );
KIO::StoredTransferJob* stJob = qobject_cast<KIO::StoredTransferJob*>( job );
QStringList newList;
if(format=="json"){
//if(format=="json"){
newList = readUsersScreenNameFromJson( theAccount, stJob->data() );
} else {
newList = readUsersScreenNameFromXml( theAccount, stJob->data() );
}
//} else {
// newList = readUsersScreenNameFromXml( theAccount, stJob->data() );
//}
friendsList << newList;
if ( newList.count() == 100 ) {
doRequestFriendsScreenName( theAccount, ++friendsPage );
......@@ -282,7 +282,7 @@ void LaconicaMicroBlog::slotRequestFriendsScreenName(KJob* job)
}
}
QStringList LaconicaMicroBlog::readUsersScreenNameFromXml(Choqok::Account* theAccount, const QByteArray& buffer)
/*QStringList LaconicaMicroBlog::readUsersScreenNameFromXml(Choqok::Account* theAccount, const QByteArray& buffer)
{
kDebug();
QStringList list;
......@@ -320,7 +320,7 @@ QStringList LaconicaMicroBlog::readUsersScreenNameFromXml(Choqok::Account* theAc
node = node.nextSibling();
}
return list;
}
}*/
void LaconicaMicroBlog::fetchConversation(Choqok::Account* theAccount, const ChoqokId& conversationId)
{
......@@ -360,11 +360,11 @@ void LaconicaMicroBlog::slotFetchConversation(KJob* job)
i18n("Fetching conversation failed. %1", job->errorString()), Normal );
} else {
KIO::StoredTransferJob *stj = qobject_cast<KIO::StoredTransferJob *> ( job );
if(format=="json"){
//if(format=="json"){
posts = readTimelineFromJson ( theAccount, stj->data() );
} else {
posts = readTimelineFromXml ( theAccount, stj->data() );
}
//} else {
// posts = readTimelineFromXml ( theAccount, stj->data() );
//}
if( !posts.isEmpty() ){
emit conversationFetched(theAccount, conversationId, posts);
}
......
......@@ -80,7 +80,7 @@ private:
public:
virtual void requestFriendsScreenName(TwitterApiAccount* theAccount);
virtual QStringList readUsersScreenNameFromXml(Choqok::Account* theAccount, const QByteArray& buffer);
//virtual QStringList readUsersScreenNameFromXml(Choqok::Account* theAccount, const QByteArray& buffer);
protected Q_SLOTS:
virtual void slotFetchConversation( KJob* job );
......
......@@ -25,6 +25,8 @@
#include "twitteraccount.h"
#include "twittermicroblog.h"
#include <KDebug>
#include <iostream>
class TwitterAccount::Private
{
......@@ -39,7 +41,8 @@ TwitterAccount::TwitterAccount(TwitterMicroBlog* parent, const QString &alias)
{
setHost("https://api.twitter.com");
setUploadHost("https://upload.twitter.com");
setApi("1");
setApi("1.1");
std::cout << "Set API version to 1.1" << std::endl;
// d->lists = configGroup()->readEntry("lists", QStringList());
QStringList lists;
foreach(const QString & tm, timelineNames()){
......
......@@ -64,7 +64,7 @@ TwitterMicroBlog::TwitterMicroBlog ( QObject* parent, const QVariantList& )
kDebug();
setServiceName("Twitter");
setServiceHomepageUrl("https://twitter.com/");
timelineApiPath["Reply"] = "/statuses/mentions.%1";
timelineApiPath["Reply"] = "/statuses/mentions_timeline.%1";
setTimelineInfos();
}
void TwitterMicroBlog::setTimelineInfos()
......@@ -168,7 +168,7 @@ void TwitterMicroBlog::createPostWithAttachment(Choqok::Account* theAccount, Cho
///Documentation: http://identi.ca/notice/17779990
TwitterAccount* account = qobject_cast<TwitterAccount*>(theAccount);
KUrl url = account->uploadUrl();
url.addPath ( "/statuses/update_with_media.xml" );
url.addPath ( "/statuses/update_with_media.json" );
QByteArray fileContentType = KMimeType::findByUrl( picUrl, 0, true )->name().toUtf8();
QMap<QString, QByteArray> formdata;
......
......@@ -30,6 +30,9 @@
#include <kio/job.h>
#include <QDomElement>
#include "choqokbehaviorsettings.h"
#include "twitteraccount.h"
#include <QtOAuth/QtOAuth>
#include <qjson/parser.h>
const QRegExp TwitterSearch::m_rId("tag:search.twitter.com,[0-9]+:([0-9]+)");
......@@ -70,13 +73,45 @@ void TwitterSearch::requestSearchResults(const SearchInfo &searchInfo,
{
kDebug();
KUrl url = buildUrl( searchInfo.query, searchInfo.option, sinceStatusId, count, page );
QOAuth::ParamMap param;
QString query = searchInfo.query;
int option = searchInfo.option;
QString formattedQuery = mSearchCode[option] + query;
KUrl url( "https://api.twitter.com/1.1/search/tweets.json" );
KUrl tmpUrl(url);
url.addQueryItem("q", formattedQuery);
QString q = url.query();
param.insert( "q", q.mid(q.indexOf('=') + 1).toLatin1() );
if( !sinceStatusId.isEmpty() ) {
url.addQueryItem( "since_id", sinceStatusId );
param.insert( "since_id", sinceStatusId.toLatin1() );
}
int cntStr = Choqok::BehaviorSettings::countOfPosts();
if( count && count <= 100 ) // Twitter API specifies a max count of 100
cntStr = count;
else
cntStr = 100;
url.addQueryItem( "count", QString::number(cntStr) );
param.insert( "count", QString::number(cntStr).toLatin1() );
if( page > 1 ) {
url.addQueryItem( "page", QString::number( page ) );
param.insert( "page", QString::number( page ).toLatin1() );
}
kDebug()<<url;
KIO::StoredTransferJob *job = KIO::storedGet( url, KIO::Reload, KIO::HideProgressInfo );
if( !job ) {
kError() << "Cannot create an http GET request!";
return;
}
TwitterAccount *acc = qobject_cast<TwitterAccount*>(searchInfo.account);
QByteArray auth = acc->oauthInterface()->createParametersString( tmpUrl.url(), QOAuth::GET, acc->oauthToken(),
acc->oauthTokenSecret(), QOAuth::HMAC_SHA1,
param, QOAuth::ParseForHeaderArguments );
job->addMetaData("customHTTPHeader", "Authorization: " + auth);
mSearchJobs[job] = searchInfo;
connect( job, SIGNAL( result( KJob* ) ), this, SLOT( searchResultsReturned( KJob* ) ) );
job->start();
......@@ -99,124 +134,57 @@ void TwitterSearch::searchResultsReturned(KJob* job)
return;