stefanuros / dartTwitterAPI

A dart class to make accessing the Twitter API from dart and flutter a bit easier.
https://pub.dev/packages/twitter_api
BSD 2-Clause "Simplified" License
11 stars 3 forks source link

Getting 404 on oauth/request_token #3

Closed HarshitDoshi closed 4 years ago

HarshitDoshi commented 4 years ago

Hello!

I am trying to implement "Login with Twitter" using the developer guide given here.

I am trying to use this package for the same, but I always get a 404. Other endpoints work but the oauth/request_token doesn't seem to work.

My code for the same is as below:

import 'package:twitter_api/twitter_api.dart';

Future main() async {
  String consumerApiKey = "my-api-key";
  String consumerApiSecret =
      "my-api-secret";
  String accessToken = "my-access-token";
  String accessTokenSecret = "my-access-secret";

  final _twitterOauth = twitterApi(
    consumerKey: consumerApiKey,
    consumerSecret: consumerApiSecret,
    token: accessToken,
    tokenSecret: accessTokenSecret,
  );

  Future twitterRequest = _twitterOauth.getTwitterRequest(
    "POST",
    "oauth/request_token",
    options: {
      "oauth_callback": "mytwitterapphd://callback",
    },
    timeout: 10,
  );

  var res = await twitterRequest;
  print(res);
  print(res.statusCode);
  print(res.body);
}

I have the callback registered on my Twitter developer console. I have enabled Sign in with Twitter on the same console. I am 100% sure that I have the correct keys, tokens and secrets. I have triple checked everything.

Is there anything that I am missing or anything I am doing wrong here?

HarshitDoshi commented 4 years ago

The output I am getting when I run file in terminal:

Instance of 'Response'
404
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="Content-Language" content="en-us">
    <meta name="robots" content="noindex, nofollow">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Twitter / ?</title>
    <link href="https://abs.twimg.com/favicons/favicon.ico" rel="shortcut icon" type="image/x-icon">
    <link rel="stylesheet" href="https://abs.twimg.com/errors/fullscreen_errors-4e29aecc89be6d500979e19c3bd72aa2.css">  </head>
  <body>
    <div class="errorpage-topbar">
      <div class="errorpage-global-nav">
        <div class="errorpage-global-nav-inner">
          <div class="errorpage-container">
            <ul class="errorpage-nav">
              <li>
                <a href="https://twitter.com"><img class="errorpage-bird" srcset='https://abs.twimg.com/errors/logo23x19.png 1x, https://abs.twimg.com/errors/logo23x19@2x.png 2x' src="https://abs.twimg.com/errors/logo23x19.png" alt="Twitter"></a>
              </li>
            </ul>
            <div class="errorpage-pull-right">
              <ul class="errorpage-nav">
                <li><a href="https://twitter.com" id="homeLink">Home &rarr;</a></li>
              </ul>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div>
      <div class="errorpage-body-content">

          <h1>Sorry, that page doesn’t exist!</h1>
          <p>You can <a href="https://twitter.com/search-home">search Twitter</a> using the search box below or <a href="https://twitter.com">return to the homepage</a>.</p>
          <form class="search-404" action="https://twitter.com/search" method="get">
            <input id="search_q" name="q" type="text" aria-label="Search query" placeholder="Search for a topic, full 
name, or @username">
            <input class="errorpage-btn" id="search_submit" type="submit" value="Search">
          </form>

        <div class="errorpage-footer">
          <ul class="errorpage-languages">

              <li><a data-language="ar" data-dir="rtl" href="#">العربية</a></li>

              <li><a data-language="bg" data-dir="ltr" href="#">Български език</a></li>

              <li><a data-language="bn" data-dir="ltr" href="#">বাংলা</a></li>

              <li><a data-language="ca" data-dir="ltr" href="#">Català</a></li>

              <li><a data-language="cs" data-dir="ltr" href="#">Čeština</a></li>

              <li><a data-language="da" data-dir="ltr" href="#">Dansk</a></li>

              <li><a data-language="de" data-dir="ltr" href="#">Deutsch</a></li>

              <li><a data-language="el" data-dir="ltr" href="#">Ελληνικά</a></li>

              <li><a data-language="en" data-dir="" href="#">English</a></li>

              <li><a data-language="en-gb" data-dir="ltr" href="#">English UK</a></li>

              <li><a data-language="es" data-dir="ltr" href="#">Español</a></li>

              <li><a data-language="fa" data-dir="rtl" href="#">فارسی</a></li>

              <li><a data-language="fi" data-dir="ltr" href="#">Suomi</a></li>

              <li><a data-language="fil" data-dir="ltr" href="#">Filipino</a></li>

              <li><a data-language="fr" data-dir="ltr" href="#">Français</a></li>

              <li><a data-language="gu" data-dir="ltr" href="#">ગુજરાતી</a></li>

              <li><a data-language="he" data-dir="rtl" href="#">עִבְרִית</a></li>

              <li><a data-language="hi" data-dir="ltr" href="#">हिन्दी</a></li>

              <li><a data-language="hr" data-dir="ltr" href="#">Hrvatski</a></li>

              <li><a data-language="hu" data-dir="ltr" href="#">Magyar</a></li>

              <li><a data-language="id" data-dir="ltr" href="#">Bahasa Indonesia</a></li>

              <li><a data-language="it" data-dir="ltr" href="#">Italiano</a></li>

              <li><a data-language="ja" data-dir="ltr" href="#">日本語</a></li>

              <li><a data-language="kn" data-dir="ltr" href="#">ಕನ್ನಡ</a></li>

              <li><a data-language="ko" data-dir="ltr" href="#">한국어</a></li>

              <li><a data-language="mr" data-dir="ltr" href="#">मराठी</a></li>

              <li><a data-language="msa" data-dir="ltr" href="#">Bahasa Melayu</a></li>

              <li><a data-language="nl" data-dir="ltr" href="#">Nederlands</a></li>

              <li><a data-language="no" data-dir="ltr" href="#">Norsk</a></li>

              <li><a data-language="pl" data-dir="ltr" href="#">Polski</a></li>

              <li><a data-language="pt" data-dir="ltr" href="#">Português</a></li>

              <li><a data-language="ro" data-dir="ltr" href="#">Română</a></li>

              <li><a data-language="ru" data-dir="ltr" href="#">Русский</a></li>

              <li><a data-language="sk" data-dir="ltr" href="#">Slovenčina</a></li>

              <li><a data-language="sr" data-dir="ltr" href="#">Српски</a></li>

              <li><a data-language="sv" data-dir="ltr" href="#">Svenska</a></li>

              <li><a data-language="ta" data-dir="ltr" href="#">தமிழ்</a></li>

              <li><a data-language="th" data-dir="ltr" href="#">ภาษาไทย</a></li>

              <li><a data-language="tr" data-dir="ltr" href="#">Türkçe</a></li>

              <li><a data-language="uk" data-dir="ltr" href="#">Українська мова</a></li>

              <li><a data-language="vi" data-dir="ltr" href="#">Tiếng Việt</a></li>

              <li><a data-language="zh-cn" data-dir="ltr" href="#">简体中文</a></li>

              <li><a data-language="zh-tw" data-dir="ltr" href="#">繁體中文</a></li>

          </ul>
          <ul>
            <li dir="ltr">&copy; Twitter <span id="copyright-year"></span></li>
            <li><a href="https://about.twitter.com/">About</a></li>
            <li><a href="https://support.twitter.com/">Help Center</a></li>
            <li><a href="https://status.twitterstat.us/">Status</a></li>
          </ul>
        </div>
      </div>
    </div>
    <script src="https://abs.twimg.com/errors/404-174a1f1a41465b8e7b205e9551995267.js"></script>
  </body>
</html>
stefanuros commented 4 years ago

Hi,

Thank you for bringing this to my attention. I will try to take a look at this soon and will update you as soon as I have info.

HarshitDoshi commented 4 years ago

Hi @stefanuros !

I found the solution.

It was my lack of proper reading of your GitHub README.md that led me to such errors. I didn't read the part where you mention that user authentication is not supported.

I found a solution for user authentication too. I can share it if you are interested. It's just a minor change in the baseUrl.

Should I go ahead and send in a PR for the same?

Also, I will go ahead and close this issue! :)

Thank you!

stefanuros commented 4 years ago

Hi, sorry I didn't catch that that was the issue, I haven't been able to look at the code in a while. If you want to make a pr with the user authentication implementation, that would be brilliant.

Thanks

HarshitDoshi commented 4 years ago

Hi @stefanuros !

Sorry, I got busy with work afterwards, but I am going to work on this now and send in a PR.

Thanks! :)