Facebook Applications

From no name for this wiki
Jump to: navigation, search

Samples

Facebook Connect

Facebook Connect: http://wiki.developers.facebook.com/index.php/Facebook_Connect

Clients

.net

Libraries

Signatur validieren

Signatur validieren:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using Testmaster.Business;
using Testmaster.Trace;
using System.Text;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Security.Cryptography;
 
 
namespace Testmaster.Facebook 
{
 
 
   public class FacebookConnect {
 
      private static Log log = LogFactory.Instance.GetLog(typeof(FacebookConnect));
 
      public static bool VerifySignature(NameValueCollection nameValueCollection, string appsecret) 
      { 
         string signature = nameValueCollection["fb_sig"]; 
         if (String.IsNullOrEmpty(signature)) 
         {
            log.Debug("Keine Signatur vorhanden");
            return false; 
         }
 
         IEnumerable<string> keyValuePairs  =   (from key in nameValueCollection.AllKeys where key.StartsWith("fb_sig_") orderby key select key.Substring(7) + "=" + nameValueCollection[key]);
         StringBuilder sb = new StringBuilder(); 
         foreach(string keyValuePair in keyValuePairs)
         {        
            log.Debug("KeyValuePair: ",keyValuePair);
            sb.Append(keyValuePair);
         }
         sb.Append(appsecret);        
         string s = sb.ToString();
         log.Debug("String to Hash: {0}", s);        
 
         byte[] hash = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(s));
 
         StringBuilder computedSignature = new StringBuilder(); 
         foreach(byte myByte in hash)
         {
            computedSignature.AppendFormat("{0:x2}", myByte);      
         }
 
         log.Debug("computed Hash: {0}, signature: {1}", computedSignature.ToString().ToLowerInvariant(), signature.ToLowerInvariant());
 
         return computedSignature.ToString().ToLowerInvariant() == signature.ToLowerInvariant();            
      }       
 
   }
 
 
}

Java

Libraries

FBQL Sample

FBQL Sample mit TinyFB

package facebooktest;
 
import com.socialjava.TinyFBClient;
import java.util.TreeMap;
 
public class Main {
 
    public static void main(String[] args) {
        TinyFBClient fb = new TinyFBClient("key","secret");
        TreeMap tm = new TreeMap();
        tm.put("query", "SELECT name FROM user WHERE uid=1112344556");
        String result = fb.call("Fql.query", tm);
        System.out.println(result);
    }
 
}