[NOTE] iis 6.0上同IP SSL要設定多網站的方式

http://www.sslshopper.com/article-how-to-configure-ssl-host-headers-in-iis-6.html

By on 2012 年 05 月 18 日 | other | A comment?
標籤:,

Facebook 檢查是否加入粉絲

var fb_uid = "11111111111111";
var page_id = "123456789";

//方法一 FQL
FB.api({
    method: ‘fql.query’,
    query: ‘SELECT uid FROM page_fan WHERE uid=’ + fb_uid + ‘ AND page_id=’ + page_id
}, function (resp) {
    if (resp.length) {
        //is fans
    } else {
        //not fans
    }
});

//方法二 isFan Method
FB.api({
    method: ‘pages.isFan’,
    page_id: page_id,
    uid: fb_uid
}, function (resp) {
    if (resp == true) {
        //is fans
    } else if (resp.error_code) {
        alert(resp.error_msg);
    } else {
        //not fans
    }
});

//方法三
FB.api("/me/likes/" + page_id, function (res) {
    if (res.data) {
        if (isEmpty(res.data)) {
            //not fans
        } else {
            //is fans
        }
    } else {
        alert("check error");
    }
});

function isEmpty(obj) {
    for (var prop in obj) {
        if (obj.hasOwnProperty(prop)) return false;
    }
    return true;
}

By on 2012 年 05 月 08 日 | facebook, javascript | A comment?
標籤:, , ,

即時取得Facebook Comments Plugins 留言內容

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://ogp.me/ns/fb#">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta property="fb:app_id" content="xxxxxxxx" />
</head>
<body>
<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function(){
    FB.init({
      appId  : ‘xxxxxxxx’,
      status : true,
      cookie : true,
      xfbml  : true
    });
   
    FB.Event.subscribe(‘comment.create’, function(response) {
      var commentQuery = FB.Data.query(‘SELECT fromid, text FROM comment WHERE post_fbid=\" + response.commentID + ‘\’ AND object_id IN (SELECT comments_fbid FROM link_stat WHERE url=\" + response.href + ‘\’)');
      var userQuery = FB.Data.query(‘SELECT name FROM user WHERE uid in (select fromid from {0})’, commentQuery);

      FB.Data.waitOn([commentQuery, userQuery], function () {
        var commentRow = commentQuery.value[0];
        var userRow = userQuery.value[0];
        var commentText = commentRow.text;
        var commentUsername = userRow.name;
        alert(commentText);
      });
    });
  };

  (function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=xxxxxxxx";
    fjs.parentNode.insertBefore(js, fjs);
    }(document, ‘script’, ‘facebook-jssdk’));
</script>
<fb:comments href="http://domain.com" num_posts="2" width="470" notify="true" migrated="1"></fb:comments>
</body>
</html>

By on 2012 年 04 月 18 日 | facebook, javascript | A comment?

facebook create event and invite friend

<?php
require_once("facebook.php");

$facebook = new Facebook(array(
  ‘appId’  => ‘xxxxx’,
  ‘secret’ => ‘xxxxxxxx’,
  ‘cookie’ => true,
  ‘fileUpload’ => true
));
// Get User ID
$user = $facebook->getUser();

$file = "1.jpg";
$event_info = array(
  "privacy_type" => "SECRET",
  "name" => "用api建立活動",
  "description" => "php api建立活動",
  "category" => 1,
  "subcategory" => 1,
  "host" => "Me",
  "location" => "Taipei",
  "city" => "Taipei, Taiwan", //Must be a valid city
  "start_time" => gmmktime(0,0,0,3,20,2012),
  "end_time" => gmmktime(0,0,0,3,21,2012),
  "@file.jpg" => ‘@’.realpath($file)
);

try{
  $event_result = $facebook->api(‘me/events’,‘post’,$event_info);
  echo ‘Event Created! Event Id is: ‘.$event_result["id"];

  $ids = array("1000000001111");
  $facebook->api(array(
    ‘method’ => ‘events.invite’,
    ‘eid’ => $event_result["id"],
    ‘uids’ => $ids,
    ‘personal_message’ => "invite you",
  ));
}
catch(Exception $e){
  echo ‘Error message: ‘.$e->getMessage().‘ Error code:’.$e->getCode();
}
?>

By on 2012 年 03 月 17 日 | facebook, php | A comment?
標籤:, , , ,

Mysql EVENT JOBS

之前做的 POPO網 那邊有一個標籤的功能
但是標籤對應照片的總和我一直沒處理
原因也是因為我不想在程式端裡面做TAG COUNT的運算(至少目前為止我不想)
所以就將他拉到排程來做
MSSQL就更簡單了, 只要寫好stored procedure然後丟到jobs去就完工

Mysql的話, 先啟用 MYSQL排程 的功能
SET GLOBAL event_scheduler = ON;
SET @@global.event_scheduler = ON;
SET GLOBAL event_scheduler = 1;
SET @@global.event_scheduler = 1;

這邊我遇到了一個 Error 1577 "Cannot proceed because system table used by Event Scheduler were found damaged at server start" 的錯誤
不曉得是XAMPP的mysql設定問題還是我當初做 DB 轉移的時候造成之後的毀損
總之後來透過 mysql_upgrade -u root -p 的command來解決

接著再參考mysql 5.1的文件設定
CREATE EVENT popo_tagcount_update
ON SCHEDULE
EVERY 3 HOUR
DO
update tags set tags.tag_count = (select count(record_id) as cnt from photos_tags where photos_tags.tag_id=tags.tag_id)

這樣就加上了一筆排程
接著來看一下排程 SHOW EVENTS
會看到一筆剛剛建立的 SCHEDULE, 就完成了

如果之後要修改時間長度的話可以用
ALTER EVENT popo_tagcount_update
ON SCHEDULE
EVERY 1 HOUR

By on 2012 年 02 月 28 日 | other | A comment?
標籤:, ,

post photo to facebook album using fb token

使用版本 5.4.1

http://www.facebook.com/csharpsdk

http://docs.csharpsdk.org/

<%@ WebHandler Language="C#" Class="fb_handle" %>

using System;
using System.Web;
using System.Linq;
using System.Collections;
using System.Dynamic;
using System.IO;

public class fb_handle : IHttpHandler {
   
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";

        string fb_token = "token";
        string fb_album_name = "My Album";
        var fb = new Facebook.FacebookClient(fb_token);
        string fb_album_id;
        dynamic album = fb.Query("SELECT aid, owner, name, object_id FROM album WHERE owner=me() and name=\"" + fb_album_name + "\" AND can_upload=1");
        if (album.Count == 0)
        {
            //create album
            dynamic albumDetails = new ExpandoObject();
            albumDetails.name = fb_album_name;
            dynamic fbResult = fb.Post("/me/albums", albumDetails);
            fb_album_id = fbResult.id;
        }
        else
        {
            fb_album_id = album[0].object_id.ToString();
        }
       
        dynamic parameters = new ExpandoObject();
        parameters.message = "Hello World!";
        parameters.image = new Facebook.FacebookMediaObject { ContentType = "image/jpeg", FileName = "upload.jpg" }.SetValue(File.ReadAllBytes(context.Server.MapPath("../upload/") + "1d5698ce-7b27-42ba-b8b5-6cbb50aff164_after.jpg"));
 
        dynamic result = fb.Post("/" + fb_album_id + "/photos", parameters);
        var id = result.id;

        context.Response.Write(id);
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}

By on 2012 年 02 月 13 日 | c#.net, facebook | A comment?
標籤:, , , ,

取得好友清單跟星座轉換

<?php
header(‘P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"’);
session_start();
require ‘facebook.php’;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>好友星座</title>
</head>
<body>
<?
$facebook = new Facebook(array(
  ‘appId’  => ‘xxxxxxxxxxxxx’,
  ‘secret’ => ‘xxxxxxxxxxxxxxxxxxxxxxx’,
  ‘cookie’ => true,
));

$user = $facebook->getUser();
if ($user) {
        try {
                echo "get friend<br>";
                $all_friends_profile = $facebook->api(array(
                        ‘method’=>‘fql.query’,
                        ‘req_perms’ => ‘friends_birthday’,
                        ‘query’=>"select uid,name,birthday_date from user where uid in (select uid2 from friend where uid1=me())")
                );
                //var_dump($all_friends_profile);
                foreach($all_friends_profile as $profile){
                        echo $profile["name"]." birthay=".$profile["birthday_date"]." Horoscope=".GetHoroscope($profile["birthday_date"])."<br>";
                }
        } catch (FacebookApiException $e) {
                echo $e;
        }
       
        $logoutUrl = $facebook->getLogoutUrl();
        echo "<a href=\"$logoutUrl\">Logout</a>";
}else{
        echo "not fb user";
        $scope = "email,friends_birthday,read_stream,share_item,publish_stream,offline_access";
        $loginUrl = $facebook->getLoginUrl(array(‘scope’ => $scope));
        echo "<a href=\"$loginUrl\">Login with Facebook</a>";
}

function GetHoroscope($birth){
        $arybirth = preg_split(‘/[- :]/’,$birth);
        $nX = $arybirth[0] * 100 + $arybirth[1];
        if ( $nX >= 321 && $nX <= 419 ){
                return "牡羊";
        }else if ( $nX >= 420 && $nX <= 520 ){
                return "金牛";
        }else if ( $nX >= 521 && $nX <= 621 ){
                return "雙子";
        }else if ( $nX >= 622 && $nX <= 722 ){
                return "巨蟹";
        }else if ( $nX >= 723 && $nX <= 822 ){
                return "獅子";
        }else if ( $nX >= 823 && $nX <= 922 ){
                return "處女";
        }else if ( $nX >= 923 && $nX <= 1023 ){
                return "天秤";
        }else if ( $nX >= 1024 && $nX <= 1122 ){
                return "天蠍";
        }else if ( $nX >= 1123 && $nX <= 1221 ){
                return "射手";
        }else if ( $nX >= 1222 || $nX <= 119 ){
                return "摩羯";
        }else if ( $nX >= 120 && $nX <= 218 ){
                return "水瓶";
        }else if ( $nX >= 219 && $nX <= 320 ){
                return "雙魚";
        }else{
                return "";
        }
}
?>
</body>
</html>

By on 2011 年 12 月 15 日 | facebook, php | A comment?
標籤:, ,

Facebook 取得塗鴉牆按贊統計

$fql = "SELECT post_id, created_time, likes, message FROM stream WHERE filter_key = ‘owner’ AND source_id = me() AND created_time >= 1322697658 limit 200";
$response = $facebook->api(array(
  ‘method’ => ‘fql.query’,
  ‘query’ =>$fql,
));
               
$likeuser = array();
foreach ($response as $wall_post){
  $likecount = count($wall_post["likes"]["friends"]);
  if($likecount>0){ //have likes
    for($i=0;$i<$likecount;$i++){
      $fbuid = $wall_post["likes"]["friends"][$i];
      if (array_key_exists($fbuid, $likeuser)) {
        $likeuser[$fbuid]["like"]++;
      }else{
        $likeuser[$fbuid]["uid"] = $fbuid;
        $likeuser[$fbuid]["like"] = 1;
      }
    }
  }
}

foreach ($likeuser as $user){
  echo "<img src=\"https://graph.facebook.com/".$user["uid"]."/picture?type=square\">".$user["like"]."<br>";
}

By on | facebook, php | A comment?
標籤:, ,

ogg webm in apache

<IfModule mod_mime.c>
AddType audio/ogg .oga
AddType video/ogg .ogv
AddType application/ogg .ogg
AddType video/webm .webm
</IfModule>

要在apache裡面設定這些mime-type對應
否則影片播放會異常

By on 2011 年 12 月 13 日 | other | A comment?
標籤:, , , , , ,

透過token取得facebook user info

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Net;
using System.IO;

public partial class token : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string url = "https://graph.facebook.com/me?access_token=xxxxxxxxxxxxxxxxxxxxxxx";
        JObject myProfile = JObject.Parse(requestFBData(url));
        string myID = myProfile["id"].ToString().Replace("\"", "");
        string myName = myProfile["name"].ToString().Replace("\"", "");
        string email = myProfile["email"].ToString().Replace("\"", "");
    }

    public string requestFBData(string action)
    {
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(action);
        HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
        StreamReader sr = new StreamReader(resp.GetResponseStream());
        string results = sr.ReadToEnd();
        sr.Close();
        return results;
    }
}

$token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$me = json_decode(file_get_contents(‘https://graph.facebook.com/me?access_token=’.$token));
$user = $me->id; //user fbuid
By on 2011 年 12 月 09 日 | c#.net, facebook | A comment?
標籤:,

Asp
C#.net
Centos
Facebook
Flash
Javascript
Other
Php