2013年11月25日月曜日

View HTTP Request and Response Header

View HTTP Request and Response Header


http://web-sniffer.net/


<?php
$url='http://t.co/gW5Y1PYqNM';
echo '<pre>';
print_r(get_headers($url));

echo '<br>';
print_r(get_headers($url,1));


?>


Array
(
    [0] => HTTP/1.0 301 Moved Permanently
    [1] => cache-control: private,max-age=300
    [2] => date: Mon, 25 Nov 2013 16:16:38 GMT
    [3] => expires: Thu, 01-Jan-1970 00:00:00 GMT
    [4] => location: http://www.dodofei.com/player.php?url=https://itunes.apple.com/fr/music-video/game-over-feat.-maitre-gims/id720776643?uo=2
    [5] => server: tfe
    [6] => set-cookie: muc=1;Domain=t.co;Expires=Sat, 07-Nov-2015 16:16:38 GMT
    [7] => Content-Length: 0
    [8] => HTTP/1.1 302 Found
    [9] => Date: Mon, 25 Nov 2013 16:15:47 GMT
    [10] => Server: Apache/2.2.22 (Win32) PHP/5.4.15
    [11] => X-Powered-By: PHP/5.4.15
    [12] => location: https://itunes.apple.com/fr/music-video/game-over-feat.-maitre-gims/id720776643?uo=2&at=10ldd8
    [13] => Content-Length: 119
    [14] => Connection: close
    [15] => Content-Type: text/html; charset=UTF-8
    [16] => Content-Language: ja
    [17] => HTTP/1.0 301 Moved Permanently
    [18] => Last-Modified: Mon, 25 Nov 2013 16:16:39 GMT
    [19] => Content-Type: text/html; charset=UTF-8
    [20] => x-apple-translated-wo-url: /WebObjects/MZStore.woa/wa/viewMusicVideo?uo=2&at=10ldd8&id=720776643&cc=fr
    [21] => x-apple-orig-url: https://itunes.apple.com/fr/music-video/game-over-feat.-maitre-gims/id720776643?uo=2&at=10ldd8
    [22] => x-apple-application-site: ST11
    [23] => apple-timing-app: 3 ms
    [24] => Location: https://itunes.apple.com/fr/music-video/game-over-feat.-maitre-gims/id720776643?ign-mpt=uo%3D2
    [25] => x-apple-lokamai-no-cache: true
    [26] => x-apple-application-instance: 2125714
    [27] => x-apple-aka-ttl: Generated Mon Nov 25 08:16:39 PST 2013, Expires Mon Nov 25 08:16:39 PST 2013, TTL 0s
    [28] => x-webobjects-loadaverage: 0
    [29] => x-apple-jingle-correlation-key: DA6WMX2UOPXMS
    [30] => Content-Length: 0
    [31] => Server: ATS/4.1.0
    [32] => Expires: Mon, 25 Nov 2013 16:16:39 GMT
    [33] => Cache-Control: max-age=0, no-cache
    [34] => Pragma: no-cache
    [35] => Date: Mon, 25 Nov 2013 16:16:39 GMT
    [36] => Connection: close
    [37] => Set-Cookie: ls=1; version="1"; max-age=10; expires=Mon, 25-Nov-2013 16:16:49 GMT; path=/; domain=.apple.com
    [38] => Set-Cookie: a=QQAJAAAACwAfUZAGMTBsZGQ4AAAAACr2LcM=; version="1"; expires=Sat, 30-Nov-2013 16:16:39 GMT; path=/; domain=.apple.com
    [39] => X-Apple-Partner: origin.0
    [40] => HTTP/1.0 200 OK
    [41] => Last-Modified: Mon, 25 Nov 2013 16:16:39 GMT
    [42] => x-apple-lok-response-date: Mon Nov 25 08:16:39 PST 2013
    [43] => x-apple-translated-wo-url: /WebObjects/MZStore.woa/wa/viewMusicVideo?ign-mpt=uo%3D2&id=720776643&cc=fr
    [44] => x-apple-orig-url: https://itunes.apple.com/fr/music-video/game-over-feat.-maitre-gims/id720776643?ign-mpt=uo%3D2
    [45] => x-apple-application-site: NWK
    [46] => apple-timing-app: 149 ms
    [47] => x-apple-aka-ttl: Generated Mon Nov 25 08:16:39 PST 2013, Expires Mon Nov 25 08:17:39 PST 2013, TTL 60s
    [48] => x-apple-application-instance: 1003405
    [49] => Content-Type: text/html; charset=UTF-8
    [50] => x-webobjects-loadaverage: 0
    [51] => x-apple-jingle-correlation-key: 3U2NYZPIBCE2S
    [52] => Server: ATS/4.1.0
    [53] => Cache-Control: no-transform, max-age=60
    [54] => Date: Mon, 25 Nov 2013 16:16:39 GMT
    [55] => Connection: close
    [56] => X-Apple-Partner: origin.0
)

Array
(
    [0] => HTTP/1.0 301 Moved Permanently
    [cache-control] => private,max-age=300
    [date] => Mon, 25 Nov 2013 16:16:39 GMT
    [expires] => Thu, 01-Jan-1970 00:00:00 GMT
    [location] => Array
        (
            [0] => http://www.dodofei.com/player.php?url=https://itunes.apple.com/fr/music-video/game-over-feat.-maitre-gims/id720776643?uo=2
            [1] => https://itunes.apple.com/fr/music-video/game-over-feat.-maitre-gims/id720776643?uo=2&at=10ldd8
        )

    [server] => tfe
    [set-cookie] => muc=1;Domain=t.co;Expires=Sat, 07-Nov-2015 16:16:39 GMT
    [Content-Length] => Array
        (
            [0] => 0
            [1] => 119
            [2] => 0
        )

    [1] => HTTP/1.1 302 Found
    [Date] => Array
        (
            [0] => Mon, 25 Nov 2013 16:15:48 GMT
            [1] => Mon, 25 Nov 2013 16:16:40 GMT
            [2] => Mon, 25 Nov 2013 16:16:40 GMT
        )

    [Server] => Array
        (
            [0] => Apache/2.2.22 (Win32) PHP/5.4.15
            [1] => ATS/4.1.0
            [2] => ATS/4.1.0
        )

    [X-Powered-By] => PHP/5.4.15
    [Connection] => Array
        (
            [0] => close
            [1] => close
            [2] => close
        )

    [Content-Type] => Array
        (
            [0] => text/html; charset=UTF-8
            [1] => text/html; charset=UTF-8
            [2] => text/html; charset=UTF-8
        )

    [Content-Language] => ja
    [2] => HTTP/1.0 301 Moved Permanently
    [Last-Modified] => Array
        (
            [0] => Mon, 25 Nov 2013 16:16:40 GMT
            [1] => Mon, 25 Nov 2013 16:16:39 GMT
        )

    [x-apple-translated-wo-url] => Array
        (
            [0] => /WebObjects/MZStore.woa/wa/viewMusicVideo?uo=2&at=10ldd8&id=720776643&cc=fr
            [1] => /WebObjects/MZStore.woa/wa/viewMusicVideo?ign-mpt=uo%3D2&id=720776643&cc=fr
        )

    [x-apple-orig-url] => Array
        (
            [0] => https://itunes.apple.com/fr/music-video/game-over-feat.-maitre-gims/id720776643?uo=2&at=10ldd8
            [1] => https://itunes.apple.com/fr/music-video/game-over-feat.-maitre-gims/id720776643?ign-mpt=uo%3D2
        )

    [x-apple-application-site] => Array
        (
            [0] => ST11
            [1] => NWK
        )

    [apple-timing-app] => Array
        (
            [0] => 3 ms
            [1] => 149 ms
        )

    [Location] => https://itunes.apple.com/fr/music-video/game-over-feat.-maitre-gims/id720776643?ign-mpt=uo%3D2
    [x-apple-lokamai-no-cache] => true
    [x-apple-application-instance] => Array
        (
            [0] => 2125634
            [1] => 1003405
        )

    [x-apple-aka-ttl] => Array
        (
            [0] => Generated Mon Nov 25 08:16:40 PST 2013, Expires Mon Nov 25 08:16:40 PST 2013, TTL 0s
            [1] => Generated Mon Nov 25 08:16:39 PST 2013, Expires Mon Nov 25 08:17:39 PST 2013, TTL 60s
        )

    [x-webobjects-loadaverage] => Array
        (
            [0] => 0
            [1] => 0
        )

    [x-apple-jingle-correlation-key] => Array
        (
            [0] => 736QQ6BZ67AXU
            [1] => 3U2NYZPIBCE2S
        )

    [Expires] => Mon, 25 Nov 2013 16:16:40 GMT
    [Cache-Control] => Array
        (
            [0] => max-age=0, no-cache
            [1] => no-transform, max-age=59
        )

    [Pragma] => no-cache
    [Set-Cookie] => Array
        (
            [0] => ls=1; version="1"; max-age=10; expires=Mon, 25-Nov-2013 16:16:50 GMT; path=/; domain=.apple.com
            [1] => a=QQAJAAAACwAfUZAGMTBsZGQ4AAAAACr2LcM=; version="1"; expires=Sat, 30-Nov-2013 16:16:40 GMT; path=/; domain=.apple.com
        )

    [X-Apple-Partner] => Array
        (
            [0] => origin.0
            [1] => origin.0
        )

    [3] => HTTP/1.0 200 OK
    [x-apple-lok-response-date] => Mon Nov 25 08:16:39 PST 2013
)

2013年11月24日日曜日

Amazon アソシエイト サイトリンク

Amazon アソシエイト サイトリンク


https://affiliate-program.amazon.com/gp/associates/network/main.html

https://affiliate.amazon.co.jp/gp/associates/network/reports/main.html

2013年11月19日火曜日

YouTube Data API 動画の取得と検索

YouTube Data API のカスタム パラメータ

https://developers.google.com/youtube/2.0/reference#Searching_for_videos



<?php
/*
https://developers.google.com/youtube/2.0/developers_guide_protocol_api_query_parameters#keysp
YouTube API
 */

?>
<?php

$g=$_GET['g'];


$x=new YoutubeAPI($g);

class YoutubeAPI{
public function YoutubeAPI($key){
$API_URL='http://gdata.youtube.com/feeds/api/videos?';
$para['client']='dodofei.com';
$para['format']='5';
$para['q']=$key;
$para['max-results']='5';
$para['key']='AI***********************************Uw';
$para['v']='2';

$paras=http_build_query($para);
$xmlurl= $API_URL.$paras;

$data=simplexml_load_file($xmlurl);
//echo '<pre>';
//print_r($data);
if($data->entry){
foreach ($data->entry as $key=>$val){
$l=explode(':', $val->id);
$ll[count($ll)]=$l['3'];
}
echo implode('|',$ll);
}else{
echo 'nodata';
}
}
}
?>

2013年11月6日水曜日

setInterval(tt,3000) タイマをして、Function を実行する練習

setInterval(tt,3000)  タイマをして、Function を実行する練習


<script type="text/javascript">

var x=0;
var time1=setInterval(tt,3000);
function tt(){
x=x+1;
alert(x);
}

</script>


タイマの停止
clearTimeout(timer1);

2013年11月4日月曜日

Twitterリミッ

Twitterリミッ
https://support.twitter.com/articles/249071-twitter-apidm


現在のTwitterリミット
現時点でのアカウント毎の技術的なリミットは以下の通りです。

ダイレクトメッセージ:250件/1日
ツイート:1,000件/1日。1日あたりのリミットは、更に細かい1時間に2回間隔のリミットに分かれます。リツイートも、ツイートとして数に考慮されます。
登録メールアドレスの変更:4回/1時間
フォロー(1日):1,000件/1日。これはあくまでも技術的なリミットであり、これ以外に過剰なフォローを禁止するルールがあります。フォローリミットについての詳細は、「フォローに関するルールと留意点」をご覧ください。
フォロー(アカウント毎):2,000件を超えるフォローは、アカウント毎の特定の比率に基づき制限されます。詳細は、「フォローに関するルールと留意点」をご覧ください。
これらのリミットは、ウェブ、モバイル、電話、API等を含む、すべてのデバイスからの操作を含みます。すべてのサードパーティのアプリケーションからのAPIリクエストは、1時間毎のAPIリミットとは別にトラックされます。アカウントを複数のサードパーティアプリケーションでご利用の場合は、APIリミットにかかりやすくなりますことご理解ください。詳細は「APIレートリミット」をご覧ください。

これらのリミットは、サイト利用が多い期間中に一時的に下げる場合があります。その場合は、Twitterステータスブログでご案内致します

iTunes Search API

iTunes  Search API

http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html




2013年10月27日日曜日

ページをリロード

ページをリロード

<script type="text/javascript">
var timer = "10000";
function ReloadAddr(){
window.location.reload();
}
setTimeout(ReloadAddr, timer);
</script>

2013年10月14日月曜日

PHP JSON header('Access-Control-Allow-Origin: *') 出力

PHP JSON 出力して、異なるクライアントをアクセスするにはサーバー側に
header('Access-Control-Allow-Origin: *'); 設定が必要に成ります。


  header('Access-Control-Allow-Origin: *');
  echo $test=json_encode($this->items);

Chrome  アクセス可能
Firefox   アクセス可能

2013年10月6日日曜日

setInterval 動かない

動く     setInterval(function(){mf_getymg();},10000);
動く     setInterval(mf_getymg,10000);
動かない  setInterval(mf_getymg(),10000);
動く           setInterval('tt()',3000);   クォーテーションで括る

function mf_getymg(){
var getmg=new XMLHttpRequest();
getmg.onreadystatechange=function(){
if (getmg.readyState==4 && getmg.status==200){
mf_test(eval(getmg.responseText));
}
}
getmg.open('GET','http://192.168.11.10/YahooAPI/List.php',true);
getmg.send(null);
}

function mf_test(mg){
var newli=document.createElement('li');
newli.innerHTML=mg;
var ul=document.getElementById('test');
ul.appendChild(newli);
}



クォーテーションで括る
<script type="text/javascript">

var x=0;
setInterval('tt()',3000);
function tt(){
x=x+1;
alert(x);
}

</script>

2013年10月5日土曜日

mb_strimwidth 文字化け

変更前
echo mb_strimwidth($temp->Result->Content.'   (知恵袋)',0,280);

変更後
echo mb_strimwidth($temp->Result->Content.'   (知恵袋)',0,280,',',UTF8);

GET friendships/outgoing

<?php
include_once('../oauth/start.php');
/*
Friends & Followers
GET friendships/outgoing
https://dev.twitter.com/docs/api/1.1/get/friendships/outgoing
HTTP Methods GET

http://www.tryphp.net/2012/01/24/phpapptwitter-friendships_outgoing/
認証ユーザー(自分)がフォローリクエストを送信しているユーザーのうち、認証保留中になっているユーザーID一覧(整数値)を配列で返します。配列は構造化されたデータです。

 */

echo '<pre>';
$apiurl='https://api.twitter.com/1.1/friendships/outgoing.json';
$HTTP_Methods='GET';
$paras['cursor']='';
$paras['stringify_ids']='';

$x->twoauth($HTTP_Methods,$apiurl,$paras);
//$x->send_curl();
//var_dump($x->send_curl());
print_r($x->send_curl());

?>




Array
(
    [0] => stdClass Object
        (
            [name] => 秋葉原観察者
            [screen_name] => akibaviwer
            [id] => 122061980
            [id_str] => 122061980
            [connections] => Array
                (
                    [0] => following_requested
                )

        )

    [1] => stdClass Object
        (
            [name] => ヤマダ電機
            [screen_name] => yamada_official
            [id] => 104421866
            [id_str] => 104421866
            [connections] => Array
                (
                    [0] => following_requested
                )

        )

    [2] => stdClass Object
        (
            [name] => UZ Plant〜サザンは日本の文化〜
            [screen_name] => masyaglay
            [id] => 234254127
            [id_str] => 234254127
            [connections] => Array
                (
                    [0] => following_requested
                )

        )

    [3] => stdClass Object
        (
            [name] => ##%;p;%##
            [screen_name] => p15973736
            [id] => 956344374
            [id_str] => 956344374
            [connections] => Array
                (
                    [0] => following_requested
                )

        )

    [4] => stdClass Object
        (
            [name] => stank
            [screen_name] => herumosa123
            [id] => 733950067
            [id_str] => 733950067
            [connections] => Array
                (
                    [0] => following_requested
                )

        )

    [5] => stdClass Object
        (
            [name] => 人生詰んでレラガールズ劇場
            [screen_name] => ohpansy
            [id] => 543740099
            [id_str] => 543740099
            [connections] => Array
                (
                    [0] => following_requested
                )

        )

    [6] => stdClass Object
        (
            [name] => ユキテーヌ
            [screen_name] => yukitaine
            [id] => 120747330
            [id_str] => 120747330
            [connections] => Array
                (
                    [0] => none
                )

        )

)



2013年10月1日火曜日

GET friendships/lookup

<?php
include_once('../oauth/start.php');
/*
Friends & Followers
GET friendships/lookup
https://dev.twitter.com/docs/api/1.1/get/friendships/lookup
HTTP Methods GET

http://www.tryphp.net/2012/01/24/phpapptwitter-friendships_lookup/

 */

echo '<pre>';
$apiurl='https://api.twitter.com/1.1/friendships/lookup.json';
$HTTP_Methods='GET';
$paras['screen_name']='';
$paras['user_id']=rawurlencode('783214,6253282');

$x->twoauth($HTTP_Methods,$apiurl,$paras);
//$x->send_curl();
//var_dump($x->send_curl());
print_r($x->send_curl());

?>



Array
(
    [0] => stdClass Object
        (
            [name] => Twitter
            [screen_name] => twitter
            [id] => 783214
            [id_str] => 783214
            [connections] => Array
                (
                    [0] => none
                )

        )

    [1] => stdClass Object
        (
            [name] => Twitter API
            [screen_name] => twitterapi
            [id] => 6253282
            [id_str] => 6253282
            [connections] => Array
                (
                    [0] => none
                )

        )

)




配列を利用する;






 $us=array('159536039,1185244459,1034053130,748788386,780785840,177437663,565343646,805594118');
 $paras['user_id']=rawurlencode(implode(',',$us));



2013年9月29日日曜日

Twitter Errors

[errors] => sharing is not permissible for this status (Share validations failed)




stdClass Object
(
    [errors] => Array
        (
            [0] => stdClass Object
                (
                    [code] => 195
                    [message] => Missing or invalid url parameter.
                )

        )

)




stdClass Object
(
    [errors] => Array
        (
            [0] => stdClass Object
                (
                    [message] => Bad Authentication data
                    [code] => 215
                )

        )

)




stdClass Object
(
    [errors] => Array
        (
            [0] => stdClass Object
                (
                    [code] => 25
                    [message] => Query parameters are missing.
                )

        )

)

stdClass Object
(
    [errors] => Array
        (
            [0] => stdClass Object
                (
                    [code] => 158
                    [message] => You can't follow yourself
                )

        )

)
stdClass Object
(
    [errors] => Array
        (
            [0] => stdClass Object
                (
                    [message] => Sorry, that page does not exist
                    [code] => 34
                )

        )

)
stdClass Object
(
    [errors] => Array
        (
            [0] => stdClass Object
                (
                    [message] => Rate limit exceeded
                    [code] => 88
                )

        )

)

POST statuses/destroy/:id

<?php
include_once('../oauth/start.php');
/*
Twitter
POST statuses/destroy/:id
https://dev.twitter.com/docs/api/1.1/post/statuses/destroy/%3Aid
https://api.twitter.com/1.1/statuses/destroy/:id.json
HTTP Methods POST

 */

echo '<pre>';
$apiurl='https://api.twitter.com/1.1/statuses/destroy/382527698498621440.json';
$HTTP_Methods='POST';
$paras['id']='';
$paras['trim_user']='true';


$x->twoauth($HTTP_Methods,$apiurl,$paras);
//$x->send_curl();
//var_dump($x->send_curl());
print_r($x->send_curl());

?>



stdClass Object
(
    [geo] => 
    [entities] => stdClass Object
        (
            [urls] => Array
                (
                )

            [hashtags] => Array
                (
                )

            [user_mentions] => Array
                (
                )

        )

    [user] => stdClass Object
        (
            [id] => 371259452
            [id_str] => 371259452
        )

    [in_reply_to_user_id] => 
    [contributors] => 
    [place] => 
    [retweet_count] => 0
    [source] => ツイッターの種
    [in_reply_to_status_id_str] => 
    [coordinates] => 
    [retweeted] => 
    [id] => 3.82527698499E+17
    [in_reply_to_user_id_str] => 
    [in_reply_to_status_id] => 
    [truncated] => 
    [in_reply_to_screen_name] => 
    [created_at] => Tue Sep 24 15:31:25 +0000 2013
    [id_str] => 382527698498621440
    [text] => 福島県漁連 試験操業を再開へ
    [favorited] => 
)

GET statuses/retweets/:id

$apiurl='https://api.twitter.com/1.1/statuses/retweets/373439054957670401.json';
$HTTP_Methods='GET';
$paras['id']=''; //id.json
$paras['count']='1';
$paras['trim_user']='true';


$x->twoauth($HTTP_Methods,$apiurl,$paras);
//$x->send_curl();
//var_dump($x->send_curl());
print_r($x->send_curl());



Array
(
    [0] => stdClass Object
        (
            [created_at] => Sun Sep 29 01:37:32 +0000 2013
            [id] => 3.84129784651E+17
            [id_str] => 384129784650801152
            [text] => RT @masason: 被災地高校生の留学支援「TOMODACHIリーダーシップ・プログラム」に参加した100人が無事帰国。米国での学びと被災地の現状を9/1(日)13:30~アップルストア銀座にて報告します。ぜひ高校生の生の声を聞きに来て下さい。
            [source] => Twitter for iPhone
            [truncated] => 
            [in_reply_to_status_id] => 
            [in_reply_to_status_id_str] => 
            [in_reply_to_user_id] => 
            [in_reply_to_user_id_str] => 
            [in_reply_to_screen_name] => 
            [user] => stdClass Object
                (
                    [id] => 118879992
                    [id_str] => 118879992
                )

            [geo] => 
            [coordinates] => 
            [place] => 
            [contributors] => 
            [retweeted_status] => stdClass Object
                (
                    [created_at] => Fri Aug 30 13:36:23 +0000 2013
                    [id] => 3.73439054958E+17
                    [id_str] => 373439054957670401
                    [text] => 被災地高校生の留学支援「TOMODACHIリーダーシップ・プログラム」に参加した100人が無事帰国。米国での学びと被災地の現状を9/1(日)13:30~アップルストア銀座にて報告します。ぜひ高校生の生の声を聞きに来て下さい。
                    [source] => TwitRocker2 for iPad
                    [truncated] => 
                    [in_reply_to_status_id] => 
                    [in_reply_to_status_id_str] => 
                    [in_reply_to_user_id] => 
                    [in_reply_to_user_id_str] => 
                    [in_reply_to_screen_name] => 
                    [user] => stdClass Object
                        (
                            [id] => 99008565
                            [id_str] => 99008565
                        )

                    [geo] => 
                    [coordinates] => 
                    [place] => 
                    [contributors] => 
                    [retweet_count] => 247
                    [favorite_count] => 104
                    [entities] => stdClass Object
                        (
                            [hashtags] => Array
                                (
                                )

                            [symbols] => Array
                                (
                                )

                            [urls] => Array
                                (
                                )

                            [user_mentions] => Array
                                (
                                )

                        )

                    [favorited] => 
                    [retweeted] => 
                    [lang] => ja
                )

            [retweet_count] => 247
            [favorite_count] => 0
            [entities] => stdClass Object
                (
                    [hashtags] => Array
                        (
                        )

                    [symbols] => Array
                        (
                        )

                    [urls] => Array
                        (
                        )

                    [user_mentions] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [screen_name] => masason
                                    [name] => 孫正義
                                    [id] => 99008565
                                    [id_str] => 99008565
                                    [indices] => Array
                                        (
                                            [0] => 3
                                            [1] => 11
                                        )

                                )

                        )

                )

            [favorited] => 
            [retweeted] => 
            [lang] => ja
        )

)

Twitter API optional trim_user

$apiurl='https://api.twitter.com/1.1/statuses/user_timeline.json';
$HTTP_Methods='GET';
$paras['user_id']='';
$paras['screen_name']='';
$paras['since_id']='382527698498621440';
$paras['count']='';
$paras['page']='';
$paras['max_id']='383209620551921666';
$paras['trim_user']='true';
$paras['include_entities']='true';
$paras['exclude_replies']='true';
$paras['contributor_details']='true';
$paras['include_rts']='true';

$x->twoauth($HTTP_Methods,$apiurl,$paras);
//$x->send_curl();
//var_dump($x->send_curl());
print_r($x->send_curl());


例  trim_user = true
Array
(
    [0] => stdClass Object
        (
            [created_at] => Thu Sep 26 12:41:07 +0000 2013
            [id] => 3.83209620552E+17
            [id_str] => 383209620551921666
            [text] => 楽天Vなるか、9回マー君登場
            [source] => ツイッターの種
            [truncated] => 
            [in_reply_to_status_id] => 
            [in_reply_to_status_id_str] => 
            [in_reply_to_user_id] => 
            [in_reply_to_user_id_str] => 
            [in_reply_to_screen_name] => 
            [user] => stdClass Object
                (
                    [id] => 371259452
                    [id_str] => 371259452
                )

            [geo] => 
            [coordinates] => 
            [place] => 
            [contributors] => 
            [retweet_count] => 0
            [favorite_count] => 0
            [entities] => stdClass Object
                (
                    [hashtags] => Array
                        (
                        )

                    [symbols] => Array
                        (
                        )

                    [urls] => Array
                        (
                        )

                    [user_mentions] => Array
                        (
                        )

                )

            [favorited] => 
            [retweeted] => 
            [lang] => ja
        )

)

例  trim_user = false

Array
(
    [0] => stdClass Object
        (
            [created_at] => Thu Sep 26 12:41:07 +0000 2013
            [id] => 3.83209620552E+17
            [id_str] => 383209620551921666
            [text] => 楽天Vなるか、9回マー君登場
            [source] => ツイッターの種
            [truncated] => 
            [in_reply_to_status_id] => 
            [in_reply_to_status_id_str] => 
            [in_reply_to_user_id] => 
            [in_reply_to_user_id_str] => 
            [in_reply_to_screen_name] => 
            [user] => stdClass Object
                (
                    [id] => 371259452
                    [id_str] => 371259452
                    [name] => 黒(hei)
                    [screen_name] => hei6321
                    [location] => 日本
                    [description] => 始めまして、黒です。これからもTwitterで一緒にYahooApiを遊ぼう!!!. http://t.co/GbOnNHxhTg
                    [url] => http://t.co/fw9Qmf2t3W
                    [entities] => stdClass Object
                        (
                            [url] => stdClass Object
                                (
                                    [urls] => Array
                                        (
                                            [0] => stdClass Object
                                                (
                                                    [url] => http://t.co/fw9Qmf2t3W
                                                    [expanded_url] => http://apiyahoo.hp2.jp/
                                                    [display_url] => apiyahoo.hp2.jp
                                                    [indices] => Array
                                                        (
                                                            [0] => 0
                                                            [1] => 22
                                                        )

                                                )

                                        )

                                )

                            [description] => stdClass Object
                                (
                                    [urls] => Array
                                        (
                                            [0] => stdClass Object
                                                (
                                                    [url] => http://t.co/GbOnNHxhTg
                                                    [expanded_url] => http://loto6.pa.land.to/
                                                    [display_url] => loto6.pa.land.to
                                                    [indices] => Array
                                                        (
                                                            [0] => 43
                                                            [1] => 65
                                                        )

                                                )

                                        )

                                )

                        )

                    [protected] => 
                    [followers_count] => 1677
                    [friends_count] => 1825
                    [listed_count] => 0
                    [created_at] => Sat Sep 10 14:13:36 +0000 2011
                    [favourites_count] => 22
                    [utc_offset] => 32400
                    [time_zone] => Tokyo
                    [geo_enabled] => 1
                    [verified] => 
                    [statuses_count] => 2569
                    [lang] => ja
                    [contributors_enabled] => 
                    [is_translator] => 
                    [profile_background_color] => C0DEED
                    [profile_background_image_url] => http://abs.twimg.com/images/themes/theme1/bg.png
                    [profile_background_image_url_https] => https://abs.twimg.com/images/themes/theme1/bg.png
                    [profile_background_tile] => 
                    [profile_image_url] => http://a0.twimg.com/profile_images/3175354807/63967ddad879ead7bae40d178cf1ebb2_normal.png
                    [profile_image_url_https] => https://si0.twimg.com/profile_images/3175354807/63967ddad879ead7bae40d178cf1ebb2_normal.png
                    [profile_banner_url] => https://pbs.twimg.com/profile_banners/371259452/1357434745
                    [profile_link_color] => 0084B4
                    [profile_sidebar_border_color] => C0DEED
                    [profile_sidebar_fill_color] => DDEEF6
                    [profile_text_color] => 333333
                    [profile_use_background_image] => 1
                    [default_profile] => 1
                    [default_profile_image] => 
                    [following] => 
                    [follow_request_sent] => 
                    [notifications] => 
                )

            [geo] => 
            [coordinates] => 
            [place] => 
            [contributors] => 
            [retweet_count] => 0
            [favorite_count] => 0
            [entities] => stdClass Object
                (
                    [hashtags] => Array
                        (
                        )

                    [symbols] => Array
                        (
                        )

                    [urls] => Array
                        (
                        )

                    [user_mentions] => Array
                        (
                        )

                )

            [favorited] => 
            [retweeted] => 
            [lang] => ja
        )

)

Twitter API optional since_id max_id

Twitter API optional


*
*
*
*
*
*  since_id     より↑のツイートを表示
*  max_id      より↓のツイートを表示
*
*
*
*
*
*
*
*

GET statuses/user_timeline

<?php
include_once('../oauth/start.php');
/*
Timelines
GET statuses/user_timeline
https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
HTTP Methods GET

認証ユーザーのステータス情報(各つぶやきとそれに関連する諸々の情報)の最大3200件分から最新20件
(count引数指定で最大200件)を取得します。 screen_name や user_id のパラメータを指定すれば
他のユーザーのステータス情報を取得できます。ただしそのユーザー情報が非表示設定されていない場合か、
認証ユーザーからのフォローリクエストを承諾している場合に限ります。返されたタイムラインは、Twitter.com
にログインするときにユーザー自身が見るのと同じタイムライン情報です。このメソッドは、最大3200件まで
ステータス情報を返します。include_rts が true または 1 になっていれば、リツイートも含めて最大
3200件のステータス情報を返します。

このメソッドは、include_rtsパラメータが設定されていない限り、XMLとJSON形式において、リツイートの
つぶやきは含まれません。RSSとAtom形式の場合は、常にステータス情報にリツイートが含まれます。

http://www.tryphp.net/2012/01/10/phpapptwitter-user_timeline/
http://twinavi.jp/guide/section/twitter/glossary/メンション(Mentions)とは

 */

echo '<pre>';
$apiurl='https://api.twitter.com/1.1/statuses/user_timeline.json';
$HTTP_Methods='GET';
$paras['user_id']='';
$paras['screen_name']='masason';
$paras['since_id']='371636752991010817';
$paras['count']='';
$paras['page']='';
$paras['max_id']='';
$paras['trim_user']='true';
$paras['include_entities']='true';
$paras['exclude_replies']='';
$paras['contributor_details']='';
$paras['include_rts']='';

$x->twoauth($HTTP_Methods,$apiurl,$paras);
//$x->send_curl();
//var_dump($x->send_curl());
print_r($x->send_curl());

?>





Array
(
    [0] => stdClass Object
        (
            [created_at] => Fri Aug 30 13:36:23 +0000 2013
            [id] => 3.73439054958E+17
            [id_str] => 373439054957670401
            [text] => 被災地高校生の留学支援「TOMODACHIリーダーシップ・プログラム」に参加した100人が無事帰国。米国での学びと被災地の現状を9/1(日)13:30~アップルストア銀座にて報告します。ぜひ高校生の生の声を聞きに来て下さい。
            [source] => TwitRocker2 for iPad
            [truncated] => 
            [in_reply_to_status_id] => 
            [in_reply_to_status_id_str] => 
            [in_reply_to_user_id] => 
            [in_reply_to_user_id_str] => 
            [in_reply_to_screen_name] => 
            [user] => stdClass Object
                (
                    [id] => 99008565
                    [id_str] => 99008565
                )

            [geo] => 
            [coordinates] => 
            [place] => 
            [contributors] => 
            [retweet_count] => 247
            [favorite_count] => 104
            [entities] => stdClass Object
                (
                    [hashtags] => Array
                        (
                        )

                    [symbols] => Array
                        (
                        )

                    [urls] => Array
                        (
                        )

                    [user_mentions] => Array
                        (
                        )

                )

            [favorited] => 
            [retweeted] => 
            [lang] => ja
        )

)

GET statuses/mentions_timeline

GET statuses/mentions_timeline

<?php
include_once('../oauth/start.php');
/*
Timelines
GET statuses/mentions_timeline
https://api.twitter.com/1.1/statuses/mentions_timeline.json
HTTP Methods GET

認証ユーザーへのつぶやきを示す@ユーザー名を含むステータス情報(各つぶやきとそれに関連する諸々の情報)の最新20件
(count引数指定で最大200件)を返します。返されたタイムラインは、Twitter.com 上の mentions(@関連) の表示と
同じです。誰かが投稿した、自分へに対するつぶやき「@自分」を含む「メンションつぶやき」一覧を取得します。mentions(@関連)
 の一覧と同じです。

このメソッドは最大800件までステータス情報を返します。include_rts が true または 1 になっていれば、リツイートも含めて
最大800件のステータス情報を返します。

このメソッドは、include_rtsパラメータが設定されていない限り、XMLとJSON形式において、リツイートのつぶやきは含まれません。
RSSとAtom形式の場合は、常にステータス情報にリツイートが含まれます。

http://www.tryphp.net/2012/01/05/phpapptwitter-mentions/
http://twinavi.jp/guide/section/twitter/glossary/メンション(Mentions)とは

 */

echo '<pre>';
$apiurl='https://api.twitter.com/1.1/statuses/mentions_timeline.json';
$HTTP_Methods='GET';
$paras['count']='5'; //取得結果数
$paras['page']='5'; //取得ページ数
$paras['since_id']='';
$paras['max_id']='';
$paras['trim_user']='true'; //ユーザー情報含まない
$paras['contributor_details']='';
$paras['include_entities']='false'; //実体含まない
$x->twoauth($HTTP_Methods,$apiurl,$paras);
//$x->send_curl();
print_r($x->send_curl());

?>





Array
(
    [0] => stdClass Object
        (
            [created_at] => Mon Aug 05 22:46:55 +0000 2013
            [id] => 3.64517905771E+17
            [id_str] => 364517905771139072
            [text] => @hei6321 雨?
            [source] => Tweetbot for iOS
            [truncated] => 
            [in_reply_to_status_id] => 3.6451560366E+17
            [in_reply_to_status_id_str] => 364515603660292096
            [in_reply_to_user_id] => 371259452
            [in_reply_to_user_id_str] => 371259452
            [in_reply_to_screen_name] => hei6321
            [user] => stdClass Object
                (
                    [id] => 44096288
                    [id_str] => 44096288
                )

            [geo] => 
            [coordinates] => 
            [place] => 
            [contributors] => 
            [retweet_count] => 0
            [favorite_count] => 0
            [favorited] => 
            [retweeted] => 
            [lang] => ja
        )

    [1] => stdClass Object
        (
            [created_at] => Fri Aug 02 11:14:38 +0000 2013
            [id] => 3.63256521582E+17
            [id_str] => 363256521582313472
            [text] => 2回目以降はほんま面倒ですよ。 RT @hei6321
            [source] => web
            [truncated] => 
            [in_reply_to_status_id] => 3.632558533E+17
            [in_reply_to_status_id_str] => 363255853299666946
            [in_reply_to_user_id] => 371259452
            [in_reply_to_user_id_str] => 371259452
            [in_reply_to_screen_name] => hei6321
            [user] => stdClass Object
                (
                    [id] => 248336266
                    [id_str] => 248336266
                )

            [geo] => 
            [coordinates] => 
            [place] => 
            [contributors] => 
            [retweet_count] => 1
            [favorite_count] => 0
            [favorited] => 
            [retweeted] => 
            [lang] => ja
        )

    [2] => stdClass Object
        (
            [created_at] => Fri Aug 02 11:11:11 +0000 2013
            [id] => 3.63255655404E+17
            [id_str] => 363255655404023809
            [text] => @hei6321 それは確かに!
            [source] => Tweetbot for iOS
            [truncated] => 
            [in_reply_to_status_id] => 3.63253881893E+17
            [in_reply_to_status_id_str] => 363253881892909057
            [in_reply_to_user_id] => 371259452
            [in_reply_to_user_id_str] => 371259452
            [in_reply_to_screen_name] => hei6321
            [user] => stdClass Object
                (
                    [id] => 44096288
                    [id_str] => 44096288
                )

            [geo] => 
            [coordinates] => 
            [place] => 
            [contributors] => 
            [retweet_count] => 0
            [favorite_count] => 0
            [favorited] => 
            [retweeted] => 
            [lang] => ja
        )

    [3] => stdClass Object
        (
            [created_at] => Thu Jul 25 23:30:44 +0000 2013
            [id] => 3.60542665488E+17
            [id_str] => 360542665487560704
            [text] => @hei6321 あらっ、早起きw
            [source] => Tweetbot for iOS
            [truncated] => 
            [in_reply_to_status_id] => 3.60538782816E+17
            [in_reply_to_status_id_str] => 360538782816161792
            [in_reply_to_user_id] => 371259452
            [in_reply_to_user_id_str] => 371259452
            [in_reply_to_screen_name] => hei6321
            [user] => stdClass Object
                (
                    [id] => 44096288
                    [id_str] => 44096288
                )

            [geo] => 
            [coordinates] => 
            [place] => 
            [contributors] => 
            [retweet_count] => 0
            [favorite_count] => 0
            [favorited] => 
            [retweeted] => 
            [lang] => ja
        )

    [4] => stdClass Object
        (
            [created_at] => Wed Jul 24 11:50:42 +0000 2013
            [id] => 3.60004108067E+17
            [id_str] => 360004108066885634
            [text] => @hei6321 今日も一日お疲れ様!
            [source] => Tweetbot for iOS
            [truncated] => 
            [in_reply_to_status_id] => 3.60001300312E+17
            [in_reply_to_status_id_str] => 360001300311719936
            [in_reply_to_user_id] => 371259452
            [in_reply_to_user_id_str] => 371259452
            [in_reply_to_screen_name] => hei6321
            [user] => stdClass Object
                (
                    [id] => 44096288
                    [id_str] => 44096288
                )

            [geo] => 
            [coordinates] => 
            [place] => 
            [contributors] => 
            [retweet_count] => 0
            [favorite_count] => 0
            [favorited] => 
            [retweeted] => 
            [lang] => ja
        )

)

2013年9月23日月曜日

Twitter Oauth 認証の流れ

1.    POST oauth/request_token
      https://api.twitter.com/oauth/request_token



2.    GET oauth/authorize
      https://api.twitter.com/oauth/authorize



3.   POST oauth/access_token
     https://api.twitter.com/oauth/access_token



例   http://hpapi.blogspot.jp/2013/09/post-oauthrequesttoken.html
      POST oauth/request_token 成功
      

2013年9月21日土曜日

POST oauth/access_token

POST oauth/access_token 成功

<?php
//error_reporting(E_ALL);
date_default_timezone_set('Asia/Tokyo');
?>
<?php
//new newlogin(oauth_consumer_key, oauth_consumer_key_secret, Callback_URL);
$x=new newlogin('**********', '*************', 'http://www.dodofei.com/oauthget.php');
if(!array_key_exists('oauth_token',$_REQUEST) and !array_key_exists('oauth_verifier',$_REQUEST)){
$x->request_token();
}else{
$x->access_token("http://www.dodofei.com");
}

?>
<?php
class newlogin{

public $debug='off';
public $Request_token_URL='https://api.twitter.com/oauth/request_token';
public $Authorize_URL='https://api.twitter.com/oauth/authorize';
public $Access_token_URL='https://api.twitter.com/oauth/access_token';
public $oauth_signature_method= 'HMAC-SHA1';
public $oauth_version= '1.0';
public $oauth_para=array();
  public $oauth_consumer_key='';
public $oauth_consumer_key_secret= '';
public $oauth_token_secret= '';

public function newlogin($oauth_consumer_key, $oauth_consumer_key_secret, $Callback_URL){

$this->oauth_para['oauth_callback']=$Callback_URL;
$this->oauth_para['oauth_consumer_key']=$oauth_consumer_key;
$this->oauth_para['oauth_nonce']=md5(microtime().mt_rand());
$this->oauth_para['oauth_signature_method']=$this->oauth_signature_method;
$this->oauth_para['oauth_timestamp']=time();
$this->oauth_para['oauth_version']=$this->oauth_version;
$this->oauth_consumer_key_secret=$oauth_consumer_key_secret;
}

public function request_token(){
//request_token
$signature_key=rawurlencode($this->oauth_consumer_key_secret).'&';
$respons=$this->fun_curl($this->oauth_para, $signature_key, $this->Request_token_URL,'POST');
$requestToken = array();
foreach(explode('&',$respons) as $val){
$param = explode('=',$val);
$requestToken[$param[0]] = $param[1];
}
$this->oauth_token_secret=$requestToken['oauth_token_secret'];
header(sprintf('Location: %s?%s',$this->Authorize_URL,'oauth_token='.$requestToken['oauth_token']));
}

public function authorize(){
//authorize
header(sprintf('Location: %s?%s',$this->Authorize_URL,$respons));
}

public function access_token($hpurl){
//access_token
$signature_key=rawurlencode($this->oauth_consumer_key_secret).'&'.rawurlencode($this->oauth_token_secret);
$add_para=array();
$add_para['oauth_token']=$_GET['oauth_token'];
$add_para['oauth_verifier']=$_GET['oauth_verifier'];
$para=$this->oauth_para+$add_para;
$respons=$this->fun_curl($para, $signature_key, $this->Access_token_URL,'POST');

foreach (explode('&',$respons) as $val){
$param=explode('=',$val);
setcookie($param[0],$param[1],time()+60*60*24*30*30);
}

if($respons!='error'){
//header('Location: http://www.dodofei.com/index.php?'.$respons);
header('Location: '.$hpurl);
}
}



public function fun_curl($para, $signature_key, $url, $httptype){
//oauth_signature
ksort($para);
$temp=array();
foreach ($para as $key=>$val){
if(!empty($val)){
$temp[count($temp)]=$key.'='.rawurlencode($val);
}
}

$bas_sting=implode('&',$temp);
$signature_base_string=rawurlencode($httptype).'&'.rawurlencode($url).'&'.rawurlencode($bas_sting);

if($this->debug=='on'){
echo '<pre>';
echo __LINE__;
print_r($signature_base_string);
}

// NG $this->oauth_para['oauth_signature']=rawurlencode(base64_encode(hash_hmac('sha1',$this->signature_base_string,$this->signature_key,true)));
$para['oauth_signature']=base64_encode(hash_hmac('sha1', $signature_base_string, $signature_key, true));

if($this->debug=='on'){
echo '<pre>';
echo __LINE__;
print_r($temp);
}

//Authorization: OAuth
ksort($para);
$temp1=array();
$temp2=array();

foreach ($para as $key=>$val){
if(!empty($val)){
$temp1[count($temp1)]=$key.'="'.urlencode($val).'"';
if ($key!='oauth_callback'){
$temp2[count($temp2)]=$key.'='.urlencode(rawurldecode($val));
}
}
}

$Authorization_header='Authorization: OAuth '.implode(', ',$temp1);

if($this->debug=='on'){
echo '<pre><br>';
echo __LINE__;
print_r($temp1);
}

//GET利用しない
$request_curldata=implode('&',$temp2);
if($this->debug=='on'){
echo '<pre><br>';
echo __LINE__;
print_r($temp2);
}


//CURL 送信
$ch=curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array($Authorization_header,'Content-Length:','Expect:','Content-Tpye:'));
//curl_setopt($ch, CURLOPT_HTTPHEADER, array($this->Authorization_header));

if($httptype=='GET'){
//GET動かない
$geturl=$url.'?'.$request_curldata;
curl_setopt($ch, CURLOPT_POSTFIELDS, $request_curldata);
curl_setopt($ch, CURLOPT_URL, $geturl);
curl_setopt($ch, CURLOPT_HTTPGET, true);
}

if($httptype=='POST'){
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_URL, $url);
}

$response_josn = curl_exec($ch);
$curlgetinfo=curl_getinfo($ch,CURLINFO_HEADER_OUT);
$curlgetinfo=curl_getinfo($ch);
curl_close($ch);


if($curlgetinfo['http_code']==200){
return $response_josn;
}else{
return 'error';
}
}

}


?>

2013年9月20日金曜日

GET oauth/authorize 成功

GET oauth/authorize 成功

<?php
error_reporting(E_ALL);
date_default_timezone_set('Asia/Tokyo');
?>
<?php

$x=new newlogin('***************','********************','http://www.********.com');
//http://www.********.com/?oauth_token=z4MV1x5JnEyaRaq5VbpylGoZETAX6XVv5USpZJ247N8&oauth_verifier=5eFa14MMF5DWi8LK3ZsOsyMkg7WinBGwxXNvrNUqKhE
//http://www.********.com/?denied=7ejbFPRb1oZ1Z08r8XQOauRdIeh4EkLWKH0xNFI

?>
<?php


class newlogin{

public $debug='off';
public $request_type='POST';
public $oauth_para=array();
public $Request_token_URL='https://api.twitter.com/oauth/request_token';
public $Authorize_URL='https://api.twitter.com/oauth/authorize';
public $Access_token_URL='https://api.twitter.com/oauth/access_token';
public $oauth_signature_method= 'HMAC-SHA1';
public $oauth_version= '1.0';

public $Authorization_header;
public $signature_base_string;
public $oauth_signature;
public $signature_key;
public $curlgetinfo;
public $response_josn;
public $request_curldata;


public function newlogin($oauth_consumer_key,$oauth_consumer_key_secret,$Callback_URL){

$this->oauth_para['oauth_callback']=$Callback_URL;
$this->oauth_para['oauth_consumer_key']=$oauth_consumer_key;
$this->oauth_para['oauth_nonce']=md5(microtime().mt_rand());
$this->oauth_para['oauth_signature_method']=$this->oauth_signature_method;
$this->oauth_para['oauth_timestamp']=time();
$this->oauth_para['oauth_version']=$this->oauth_version;
$this->oauth_para['oauth_signature']='';
$this->signature_key=rawurlencode($oauth_consumer_key_secret).'&';

$this->oauth_set();
$this->send_curl();
}

public function oauth_set(){
//oauth_signature
ksort($this->oauth_para);
$temp=array();
foreach ($this->oauth_para as $key=>$val){
if(!empty($val)){
$temp[count($temp)]=$key.'='.rawurlencode($val);
}
}

$bas_sting=implode('&',$temp);
$this->signature_base_string=rawurlencode($this->request_type).'&'.rawurlencode($this->Request_token_URL).'&'.rawurlencode($bas_sting);

if($this->debug=='on'){
echo '<pre>';
echo __LINE__;
print_r($this->signature_base_string);
}

// NG $this->oauth_para['oauth_signature']=rawurlencode(base64_encode(hash_hmac('sha1',$this->signature_base_string,$this->signature_key,true)));
$this->oauth_para['oauth_signature']=base64_encode(hash_hmac('sha1',$this->signature_base_string,$this->signature_key,true));
$this->oauth_signature=$this->oauth_para['oauth_signature'];

if($this->debug=='on'){
echo '<pre>';
echo __LINE__;
print_r($temp);
}

//Authorization: OAuth
ksort($this->oauth_para);
$temp1=array();
$temp2=array();

foreach ($this->oauth_para as $key=>$val){
if(!empty($val)){
$temp1[count($temp1)]=$key.'="'.urlencode($val).'"';
if ($key!='oauth_callback'){
$temp2[count($temp2)]=$key.'='.urlencode(rawurldecode($val));
}
}
}

$this->Authorization_header='Authorization: OAuth '.implode(', ',$temp1);

if($this->debug=='on'){
echo '<pre><br>';
echo __LINE__;
print_r($temp1);
}

//GET利用しない
$this->request_curldata=implode('&',$temp2);
if($this->debug=='on'){
echo '<pre><br>';
echo __LINE__;
print_r($temp2);
}

}

public function send_curl(){
//CURL 送信
$ch=curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,true);
//curl_setopt($ch, CURLOPT_HTTPHEADER, array($this->Authorization_header,'Content-Length:','Expect:','Content-Tpye:'));
curl_setopt($ch, CURLOPT_HTTPHEADER, array($this->Authorization_header));

if($this->request_type=='GET'){
//GET動かない
$geturl=$this->Request_token_URL.'?'.$this->request_curldata;
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->request_curldata);
curl_setopt($ch, CURLOPT_URL, $geturl);
curl_setopt($ch, CURLOPT_HTTPGET, true);
}

if($this->request_type=='POST'){
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_URL, $this->Request_token_URL);
}

$this->response_josn = curl_exec($ch);
$this->curlgetinfo=curl_getinfo($ch,CURLINFO_HEADER_OUT);
$this->curlgetinfo=curl_getinfo($ch);
curl_close($ch);

if($this->curlgetinfo['http_code']==200){
header(sprintf('Location: %s?%s',$this->Authorize_URL,$this->response_josn));
echo 'url Send';
}else{
sleep(3);
$this->oauth_set();
$this->send_curl();
echo 'url Error';
}
}



public function debug(){

//Debug
echo '<br>/////////Debut///////////////////';
echo '<br><pre>';
echo 'request_datas<br>';
//echo print_r($this->request_datas);
echo '<br><br>';
echo 'Signature base string<br>';
echo $this->signature_base_string;
echo '<br><br>';
echo 'oauth_signature<br>';
echo $this->oauth_signature;
echo '<br><br>';
echo 'Authorization header<br>';
echo $this->Authorization_header;
echo '<br><br>';
echo 'Curl data<br>';
echo $this->request_curldata;
echo '<br><br>';
echo 'Curl_getinfo<br>';
echo print_r($this->curlgetinfo);
echo '<br><br>';
echo 'JOSN data<br>';
echo print_r($this->response_josn);
echo '<br><br>';
echo '/////////Debut///////////////////';

}


}





?>

2013年9月19日木曜日

POST oauth/request_token 成功

POST oauth/request_token
成功、次はGET oauth/authorize


<?php
date_default_timezone_set('Asia/Tokyo');

error_reporting(E_ALL);

?>

<?php

$x=new newlogin();
$x->oauth_set();
$x->send_curl();
$x->debug();



class newlogin{

public $debug='off';
public $request_type='POST';
public $oauth_para=array();
  public $oauth_consumer_key= '***********************';
public $oauth_consumer_key_secret= '******************************';
public $oauth_token= '';
public $oauth_token_secret= '';
public $Request_token_URL='https://api.twitter.com/oauth/request_token';
public $Authorize_URL='https://api.twitter.com/oauth/authorize';
public $Access_token_URL='https://api.twitter.com/oauth/access_token';
public $Callback_URL='http://www.dodofei.com';
public $oauth_signature_method= 'HMAC-SHA1';
public $oauth_version= '1.0';


public $Authorization_header;
public $signature_base_string;
public $oauth_signature;
public $signature_key;
public $curlgetinfo;
public $response_josn;
public $request_curldata;


public function newlogin(){

$this->oauth_para['oauth_callback']=$this->Callback_URL;
$this->oauth_para['oauth_consumer_key']=$this->oauth_consumer_key;
$this->oauth_para['oauth_nonce']=md5(microtime().mt_rand());
$this->oauth_para['oauth_signature_method']=$this->oauth_signature_method;
$this->oauth_para['oauth_timestamp']=time();
$this->oauth_para['oauth_version']=$this->oauth_version;
$this->oauth_para['oauth_signature']='';
$this->signature_key=rawurlencode($this->oauth_consumer_key_secret).'&';
}

public function oauth_set(){

//oauth_signature
ksort($this->oauth_para);
$temp=array();
foreach ($this->oauth_para as $key=>$val){
if(!empty($val)){
$temp[count($temp)]=$key.'='.rawurlencode($val);
}
}

$bas_sting=implode('&',$temp);
$this->signature_base_string=rawurlencode($this->request_type).'&'.rawurlencode($this->Request_token_URL).'&'.rawurlencode($bas_sting);

if($this->debug=='on'){
echo '<pre>';
echo __LINE__;
print_r($this->signature_base_string);
}

// NG $this->oauth_para['oauth_signature']=rawurlencode(base64_encode(hash_hmac('sha1',$this->signature_base_string,$this->signature_key,true)));
$this->oauth_para['oauth_signature']=base64_encode(hash_hmac('sha1',$this->signature_base_string,$this->signature_key,true));
$this->oauth_signature=$this->oauth_para['oauth_signature'];

if($this->debug=='on'){
echo '<pre>';
echo __LINE__;
print_r($temp);
}


//Authorization: OAuth
ksort($this->oauth_para);
$temp1=array();
$temp2=array();

foreach ($this->oauth_para as $key=>$val){
if(!empty($val)){
$temp1[count($temp1)]=$key.'="'.urlencode($val).'"';
//if ($key!='oauth_callback'){
$temp2[count($temp2)]=$key.'='.urlencode(rawurldecode($val));
//}
}
}

$this->Authorization_header='Authorization: OAuth '.implode(', ',$temp1);

if($this->debug=='on'){
echo '<pre><br>';
echo __LINE__;
print_r($temp1);
}

//利用しない
$this->request_curldata=implode('&',$temp2);
if($this->debug=='on'){
echo '<pre><br>';
echo __LINE__;
print_r($temp2);
}

}



public function send_curl(){

//CURL 送信
$ch=curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,true);
//curl_setopt($ch, CURLOPT_HTTPHEADER, array($this->Authorization_header,'Content-Length:','Expect:','Content-Tpye:'));
curl_setopt($ch, CURLOPT_HTTPHEADER, array($this->Authorization_header));

if($this->request_type=='GET'){
//GET動かない
$geturl=$this->Request_token_URL.'?'.$this->request_curldata;
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->request_curldata);
curl_setopt($ch, CURLOPT_URL, $geturl);
curl_setopt($ch, CURLOPT_HTTPGET, true);
}

if($this->request_type=='POST'){
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_URL, $this->Request_token_URL);
}

//curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
//echo $this->response_josn = json_decode(curl_exec($ch));
echo $this->response_josn = curl_exec($ch);
$this->curlgetinfo=curl_getinfo($ch,CURLINFO_HEADER_OUT);
$this->curlgetinfo=curl_getinfo($ch);
//var_dump(curl_error($ch));
//var_dump($this->response_josn);
curl_close($ch);
}



public function debug(){

//Debug
echo '<br>/////////Debut///////////////////';
echo '<br><pre>';
echo 'request_datas<br>';
//echo print_r($this->request_datas);
echo '<br><br>';
echo 'Signature base string<br>';
echo $this->signature_base_string;
echo '<br><br>';
echo 'oauth_signature<br>';
echo $this->oauth_signature;
echo '<br><br>';
echo 'Authorization header<br>';
echo $this->Authorization_header;
echo '<br><br>';
echo 'Curl data<br>';
echo $this->request_curldata;
echo '<br><br>';
echo 'Curl_getinfo<br>';
echo print_r($this->curlgetinfo);
echo '<br><br>';
echo 'JOSN data<br>';
echo print_r($this->response_josn);
echo '<br><br>';
echo '/////////Debut///////////////////';

}


}





?>