开发者

Help with database schema of my Facebook application

开发者 https://www.devze.com 2023-03-28 06:42 出处:网络
I am writing a Facebook application where users give access to their pages. I am trying to lay out the best possible scheme which brings up this question. Here are some variables:

I am writing a Facebook application where users give access to their pages. I am trying to lay out the best possible scheme which brings up this question. Here are some variables:

  • Users might have more than one Facebook account
  • Need to tie Facebook account to MemberID o开发者_开发百科f my database
  • I have different Facebook applications users can use
  • I need to store a reference the page ID and access token along with the user's access token

What makes the most sense: to store the pages and their access tokens? Since the page's access token is tied to the user, it seems that you would create another table. But I believe that Facebook would store it all under the tokens table since a PageID & UserID will never be the same. Am I correct, or can someone suggest something different?

CREATE TABLE `Facebook_Users` (                                                              
                  `FacebookUser_ID` bigint(22) NOT NULL,                                                     
                  `FacebookUser_MemberID` int(11) NOT NULL,                                                  
                  `FacebookUser_Name` varchar(200) NOT NULL,                                                 
                  `FacebookUser_Email` varchar(150) default NULL,                                            
                  `FacebookUser_Birthday` date default NULL,                                                 
                  `FacebookUser_Gender` varchar(50) default NULL,                                            
                  `LastUpdatedAt` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,  
                  PRIMARY KEY  (`FacebookUser_ID`)                                                           
                ) ENGINE=MyISAM DEFAULT CHARSET=latin1                                                       

CREATE TABLE `Facebook_Tokens` (                                                                                     
                   `FacebookTokens_ID` int(11) NOT NULL auto_increment,                                                               
                   `FacebookTokens_UserID` bigint(22) NOT NULL,
                   `FacebookTokens_ApplicationID` int(11) NOT NULL,                                                                   
                   `FacebookTokens_FacebookToken` varchar(100) NOT NULL,                                                              
                   `FacebookTokens_Permissions` text,                                                                                    
                   `LastUpdatedAt` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,                          
                   PRIMARY KEY  (`FacebookTokens_ID`),                                                                                
                   UNIQUE KEY `MemberFacebook` (`FacebookTokens_UserID`,`FacebookTokens_ApplicationID`)                                       
                 ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1 


Not sure what you're planning on doing, but you're correct, Page IDs and User IDs won't ever share the same id. Also note that a user access token != page access token. When you have a user's access token, you'll need to go retrieve the specific page's access token. If you're planning on retrieving the specific page's access token when you want to manipulate the page, then you're better off consolidating this down to one table where the user access token is just a column on the user table since the access token to user relationship is 1-1 (unless you're housing multiple apps, which is looks like you might? be doing).

0

精彩评论

暂无评论...
验证码 换一张
取 消