6

最近、私は素晴らしいチュートリアルHow to Authenticate Users With Twitter OAuthを読みましたが、Twitter ID 形式を変更する前に書かれていましたが、新しい Twitter ID 形式でも機能します。

いくつか質問があります。誰かが成功したかどうか説明してください..

  • getRequestToken常に 2 つのメソッドと を呼び出すのはなぜgetAccessToken ですか? access tokenとを取得することaccess token secretですか?しかし、両方ともすでに以下のページで提供されています...

    http://dev.twitter.com/apps/ {your_app_id}/my_token.

    リクエストトークンリクエストトークンシークレットの正確な必要性は何ですか?? ただし、処理するたびに両方のトークンが異なることに気付きました。

  • 以下のメソッドからステータスを更新する場合

    $connection->post( 'statuses/update', array('status' => 'some message got from text area value' );

では、ステータスが正常に更新されたことを確認するにはどうすればよいでしょうか?? 警告メッセージを表示したい場合post has been sent successfully、PHP ページにどのように実装すればよいでしょうか??

  • どのコールバック URL が重要か、つまり、ユーザーが Twitter に投稿したり何かをしたりした後に実際にナビゲートされる場所は?

    1. Registered OAuth Callback URLアプリ開発時に書いてあるURLですか?

      http://dev.twitter.com/apps/{id_no}
      また

    2. 私たちのphpコード(config.php)で定義されているURLですか?

      define('OAUTH_CALLBACK', 'http://www.xyz.com');

    もう1つのQ'n

  • アプリケーションのアクセス拒否を処理するには?
    注:これに関する私の質問を参照してください

@Thaiの更新

私はあなたの提案に従って以下を行いました

$user_info = $connection->get('account/verify_credentials');
$status_info =$connection->get('statuses/show/', array('id' =>32320907720523776) );

echo "<pre>";
print_r($status_info);

echo "</pre> Content : <pre>";
print_r($user_info);

以下に戻ります

stdClass Object
(
    [request] => /1/statuses/show.json?id=3.2320907720524E%2B16&oauth_consumer_key=jashak..&oauth_nonce=bec...&oauth_signature=%2FMj%2B0Z7oyYNKdMn%2B%2FOJ6Ba8ccfo%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1296541384&oauth_token=223961574-cW4...&oauth_version=1.0a
    [error] => No status found with that ID.
)

注:oauth_consumer keyセキュリティ上の理由から、oauth_nonceを非表示にしていoauth_tokenます ;)

Content:
stdClass Object
(
    [follow_request_sent] => 
    [profile_link_color] => 038543
    [profile_image_url] => http://a3.twimg.com/profile_images/1215444646/minialist-photography-9_normal.jpg
    [contributors_enabled] => 
    [favourites_count] => 31
    [profile_sidebar_border_color] => EEEEEE
    [id_str] => 223961574 // this is also id_str
    [status] => stdClass Object
        (
            [retweeted] => 
            [id_str] => 32320907720523776 // this id_str i used
            [in_reply_to_status_id_str] => 
            [geo] => 
            [contributors] => 
            [source] => Black Noise
            [in_reply_to_user_id_str] => 
            [retweet_count] => 0
            [truncated] => 
            [coordinates] => 
            [created_at] => Tue Feb 01 06:14:39 +0000 2011
            [favorited] => 
            [text] => Twitter test: verify that status has been updated
            [place] => 
            [in_reply_to_screen_name] => 
            [in_reply_to_status_id] => 
            [id] => 3.2320907720524E+16
            [in_reply_to_user_id] => 
        )
   [screen_name] => ltweetl
   [profile_use_background_image] => 1
   ....
   ...

エラーが発生しましたがNo status found with that ID、どのid_strウルが言及していますか??

4

3 に答える 3

4

この回答は、特にAbrahamのTwitter-OAuth APIに当てはまるものではありませんが、TwitterのOAuthAPI全般に当てはまります。

  1. そのページはあなたにあなた自身のアプリへのあなたのアクセストークンとアクセストークンシークレットだけを与えます。これは、アプリを他のユーザーとして認証する必要がない場合は問題ありません。したがって、リクエストトークンをリクエストしたり、リクエストトークンをアクセストークンと交換したりする必要はありません。アクセストークンを使用するだけです。

    ただし、他のユーザーとして認証する場合は、必要なすべての手順を実行する必要があります。これについては、以下で簡単に説明します。

    • リクエストトークンをリクエストします。サインインにのみ使用され、ユーザーのデータへのアクセスには使用できません。リクエストトークンとリクエストトークンシークレットを取得します。リクエストトークンをリクエストするときに、認証に成功したときにTwitterがユーザーに送信するコールバックURLを指定できます。
    • 認証が完了するまで、リクエストトークンとシークレットを保持する必要があります。
    • その後、ユーザーをリダイレクトしhttp://api.twitter.com/oauth/authorize?oauth_token=てOAuthトークンを続けます。
    • ユーザーがTwitterにサインインしてアプリケーションを許可すると、TwitterはユーザーをコールバックURLに送り返します。
    • リクエストトークンをアクセストークンと交換すると、リクエストトークンは不要になるため、破棄できます。

    You can keep the access token as long as you need it. If you don't keep the access token, you will need to request the request token and exchange it for access token again, and your users will have to sign in again.

    So basically, if you are creating something that the user needs to sign in using Twitter, you need to do all the steps above to get the user signed in. If you are just using Twitter's API for yourself, you don't need the authentication step. Use your access token.

  2. You can check for the tweet's ID by checking for the id_str key on the returned response.

    If the status isn't posted, Twitter will return an error object.

  3. You can specify the default OAuth callback in the application settings page, which will be used when you don't explicitly specify a callback.

    This is required because if you somehow forget to or did not specify a callback URL, Twitter will still know where to redirect your users to.

    However, Twitter encourages that you should explicitly specify a callback URL. There are many benefit from using a callback URL, such as being able to specify any URLs as the callback. I used to benefit from this one because my Twitter client runs on two different domains, I could redirect the users back to the right place.

于 2011-01-31T13:31:18.467 に答える
0

あなたがするとき、あなたは何を得ますか:

$temp = $connection->post( 'statuses/update', array('status' => 'some message got from textarea value' );
print_r($temp);

応答 (json/xml) 形式が $temp 変数に格納されると思います。(Twitter の応答をテストするには、http://dev.twitter.com/consoleを確認してください)

config.php で定義されているコールバック URL によって、リダイレクト先が決まります。これは、このコールバック パラメータが最近 twitter API に追加されたためです。それ以前は、twitter.com のアプリ管理セクションでコールバック URL を定義することしかできませんでした。他の URL が定義されていない場合、この URL がデフォルトの URL になります。

于 2011-01-31T12:39:59.240 に答える
0

Verifier でユーザーを検証した後にのみ AccessToken と Access Token Secret を取得するためです。

Verifier は OAuth プロセスで最も重要です。そのため、 AccessToken と Access Token Secret を生成するために 1 つのリクエストを送信する必要があります。

AccessToken と Access Token Secret を取得した後、Twitter アプリケーションが彼の Info へのアクセスを許可している間、ユーザーが指定した時間だけそれを使用できます。期限が切れる.......

于 2011-01-21T06:15:58.227 に答える