Exemple #1
0
void TwitterAPI::authorize()
{
    KQOAuthRequest *authorizeRequest = new KQOAuthRequest;
    authorizeRequest->initRequest(KQOAuthRequest::TemporaryCredentials, QUrl(TwitterAPI::TwitterRequestTokenURL));
    authorizeRequest->setConsumerKey(TwitterAPI::ConsumerKey);
    authorizeRequest->setConsumerSecretKey(TwitterAPI::ConsumerSecret);
    oauthManager->executeRequest(authorizeRequest);
}
void LoginManager::upload(const QString &path, int nid, const QString &title, const QString &description, const QString& priv, const QString& license, const QString& tags)
      {
      //qDebug() << "file upload";
      KQOAuthRequest *oauthRequest = new KQOAuthRequest(this);
      QUrl url("https://api.musescore.com/services/rest/score.json");
      if (nid > 0)
            url = QUrl(QString("https://api.musescore.com/services/rest/score/%1/update.json").arg(nid));
      oauthRequest->initRequest(KQOAuthRequest::AuthorizedRequest, url);
      oauthRequest->setConsumerKey(_consumerKey);
      oauthRequest->setConsumerSecretKey(_consumerSecret);
      oauthRequest->setToken(_accessToken);
      oauthRequest->setTokenSecret(_accessTokenSecret);

      oauthRequest->setContentType("multipart/form-data");

      QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);

      QHttpPart filePart;
      filePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/octet-stream"));
      filePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"score_data\"; filename=\"temp.mscz\""));
      QFile *file = new QFile(path);
      file->open(QIODevice::ReadOnly);
      filePart.setBodyDevice(file);
      file->setParent(multiPart); // we cannot delete the file now, so delete it with the multiPart
      multiPart->append(filePart);

      QHttpPart titlePart;
      titlePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"title\""));
      titlePart.setBody(title.toUtf8());
      multiPart->append(titlePart);

      QHttpPart descriptionPart;
      descriptionPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"description\""));
      descriptionPart.setBody(description.toUtf8());
      multiPart->append(descriptionPart);

      QHttpPart privatePart;
      privatePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"private\""));
      privatePart.setBody(priv.toUtf8());
      multiPart->append(privatePart);

      QHttpPart licensePart;
      licensePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"license\""));
      licensePart.setBody(license.toUtf8());
      multiPart->append(licensePart);

      QHttpPart tagsPart;
      tagsPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"tags\""));
      tagsPart.setBody(tags.toUtf8());
      multiPart->append(tagsPart);

      connect(_oauthManager, SIGNAL(requestReady(QByteArray)),
            this, SLOT(onUploadRequestReady(QByteArray)));
      oauthRequest->setHttpMultiPart(multiPart);
      _oauthManager->executeRequest(oauthRequest);
     }
Exemple #3
0
void TwitterAPI::getAccessToken()
{
    KQOAuthRequest *accessTokenRequest = new KQOAuthRequest;
    accessTokenRequest->initRequest(KQOAuthRequest::AccessToken, QUrl(TwitterAPI::TwitterAccessTokenURL));
    accessTokenRequest->setToken(this->requestToken);
    accessTokenRequest->setTokenSecret(this->requestTokenSecret);
    accessTokenRequest->setVerifier(this->verifier);
    accessTokenRequest->setConsumerKey(this->ConsumerKey);
    accessTokenRequest->setConsumerSecretKey(this->ConsumerSecret);

    oauthManager->executeRequest(accessTokenRequest);
}
Exemple #4
0
void TwitterAPI::foo()
{
    qDebug() << "Fo!";

    KQOAuthRequest *request = new KQOAuthRequest;
    request->initRequest(KQOAuthRequest::AuthorizedRequest, QUrl("http://api.twitter.com/1/statuses/public_timeline.xml"));
    request->setHttpMethod(KQOAuthRequest::GET);
    request->setConsumerKey(this->ConsumerKey);
    request->setConsumerSecretKey(this->ConsumerSecret);
    request->setToken(oauthSettings.value("oauth_token").toString());
    request->setTokenSecret(oauthSettings.value("oauth_token_secret").toString());

    oauthManager->executeRequest(request);

//    qDebug() << "foo";
//    TwitterRequest *request = new TwitterRequest(TwitterRequest::PublicTimelineUrl, this->oauthManager);
//    request->execute();
    //TwitterRequest *request = new TwitterRequest(Request::Timeline);
}
Exemple #5
0
void TwitterAPI::singleTweet()
{
    qDebug() << "singleTweet() invoked...";

    KQOAuthRequest *request = new KQOAuthRequest;
    request->initRequest(KQOAuthRequest::AuthorizedRequest, QUrl(QString(TwitterUrl::SingleTweet).arg("20633898539028480")) );
    request->setHttpMethod(KQOAuthRequest::GET);
    request->setConsumerKey(this->ConsumerKey);
    request->setConsumerSecretKey(this->ConsumerSecret);
    request->setToken(oauthSettings.value("oauth_token").toString());
    request->setTokenSecret(oauthSettings.value("oauth_token_secret").toString());

//    QHash<QNetworkRequest::Attribute, QVariant> myCustomData;
//    myCustomData.insert(TwitterAPI::ActionAttr, QVariant("stibi rulez :)"));
//    myCustomData.insert((QNetworkRequest::Attribute) (QNetworkRequest::User+2), QVariant("foo"));
//    request->setCustomData(myCustomData);

//    oauthManager->executeRequest(request);
}
void LoginManager::getScore(int nid)
      {
      //qDebug() << "getScore";
      if (_accessToken.isEmpty() || _accessTokenSecret.isEmpty()) {
            emit getScoreError("getScore - No token");
            return;
            }
      KQOAuthRequest * oauthRequest = new KQOAuthRequest();
      oauthRequest->initRequest(KQOAuthRequest::AuthorizedRequest, QUrl(QString("https://api.musescore.com/services/rest/score/%1.json").arg(nid)));
      oauthRequest->setHttpMethod(KQOAuthRequest::GET);
      oauthRequest->setConsumerKey(_consumerKey);
      oauthRequest->setConsumerSecretKey(_consumerSecret);
      oauthRequest->setToken(_accessToken);
      oauthRequest->setTokenSecret(_accessTokenSecret);

      connect(_oauthManager, SIGNAL(requestReady(QByteArray)),
            this, SLOT(onGetScoreRequestReady(QByteArray)));

      _oauthManager->executeRequest(oauthRequest);
      }