以下のサイトを参考にしていた。2012年の記事で情報が古くなり2016年では投稿ができなくなってしまいった。~
【背景】~
以下のサイトを参考にしていた。2012年の記事で情報が古くなり、2016年では投稿ができなくなってしまった。~
他のサイトで事例がないので、試行錯誤した結果動いたのでメモ代わりに記載する。
~
~
~

【参考元サイト】~
https://vok.paburica.com/index.php?Pukiwiki%2F%E6%9B%B4%E6%96%B0%E3%81%AE%E5%BA%A6%E3%81%AB%E3%83%84%E3%82%A4%E3%83%BC%E3%83%88%E3%81%97%E3%81%9F%E3%81%84
~
~
~

【変更箇所】
funtionにコードを入れる部分が分かりいにくいので、function全体を記載する。

-lib/file.php
 // Put a data(wiki text) into a physical file(diff, backup, text)
 function page_write($page, $postdata, $notimestamp = FALSE)
 {
     if (PKWK_READONLY) return; // Do nothing
 
     $postdata = make_str_rules($postdata);
 
    // Create and write diff
    $oldpostdata = is_page($page) ? join('', get_source($page)) : '';
    $diffdata    = do_diff($oldpostdata, $postdata);
    file_write(DIFF_DIR, $page, $diffdata);
 
    // Create backup
    make_backup($page, $postdata == ''); // Is $postdata null?
 
    // Create wiki text
    file_write(DATA_DIR, $page, $postdata, $notimestamp);
 
    links_update($page);
 
    // ↓↓↓追加する START↓↓↓
    // 更新情報をツイート
    $head = '更新しました。#okaasan #おかあさんといっしょ  ';
    $guest_url = 'http://www.hanzou.jp/okaasan/index.php?' . rawurlencode($page);
    announce_tweet($head, $page, $guest_url);
    // ↑↑↑追加する END ↑↑↑
 }
~
~
~

-lib/file.php
 // ↓↓↓最終行に追加する START↓↓↓
 // [$head $title $url]というフォーマットでツイートします
 // [$head $title]部分が100文字に収まるようにトリムします
 // $urlはbit.lyを使用して短縮します
 // 引数は全てUTF-8を想定しています
 function announce_tweet($head, $title, $url)
 {
    require_once('Services/ShortURL.php');
    require_once('twitter/twitteroauth/twitteroauth.php');  ←フォルダのパスを合わせる
 
    // [$head $title]部分
    $msg = mb_substr("{$head} {$title}", 0, 100, 'UTF-8');
 
    // $urlが空でなければ、URLを短縮
    if (!empty($url))
    {
    Services_ShortURL::setServiceOptions('Bitly', array(
        // <bit.lyのユーザー名>
        'login'  => '*****',   ←変更する
 
        // <bit.lyのAPI Key>
        'apiKey' => '**********************************'   ←変更する
    ));
    $api = Services_ShortURL::factory('Bitly');
    $msg .= ' ' . $api->shorten(rawurlencode($url));
    }
    // <twitterへ登録したアプリのConsumer key>
    $consumer_key = "*************************";   ←変更する
 
    // <twitterへ登録したアプリのConsumer secret>
    $consumer_secret = "**************************************************";   ←変更する
 
    // <twitterへ登録したアプリのMy Access Token>
    $access_token = "**************************************************";   ←変更する
 
    // <twitterへ登録したアプリのAccess Token Secret>
    $access_token_secret = "*********************************************";   ←変更する
 
    // OAuthオブジェクト生成
    $to = new TwitterOAuth($consumer_key, $consumer_secret, $access_token, $access_token_secret);
 
    // ツイート
    $req = $to->OAuthRequest('https://api.twitter.com/1.1/statuses/update.json', 'POST', array(
    'status' => $msg
    ));
 }
 // ↑↑↑最終行に追加する END ↑↑↑
~
~
~
~
~

*報告等は以下にどうぞ。 [#x352c983]

#article
#comment


トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS