MySQL 将 facebook id 保存为 int 或 varchar?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7138119/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 20:53:58  来源:igfitidea点击:

Saving facebook id as int or varchar?

mysqlfacebookfacebook-graph-api

提问by Sharon Haim Pour

My question is more advisory than technical. I'm writing a Facebook app in which I am fetching some information about the user, including facebook_id.
I was wondering if I should keep the user id as INT or VARCHAR in the MySQL database?

我的问题更多的是咨询而不是技术。我正在编写一个 Facebook 应用程序,我正在其中获取有关用户的一些信息,包括 facebook_id。
我想知道是否应该在 MySQL 数据库中将用户 ID 保留为 INT 或 VARCHAR?

回答by Gustav

Facebook uses 64-bit integers (bigint)for their user ids. So you use Bigint UNSIGNED in MySQL.

Facebook 使用64 位整数 (bigint)作为其用户 ID。所以你在 MySQL 中使用 Bigint UNSIGNED。

"As a reminder, in the very near future, we will be rolling out 64 bit user IDs. We encourage you to test your applications by going to www.facebook.com/r.php?force_64bit and create test accounts with 64 bit UIDs."

“提醒一下,在不久的将来,我们将推出 64 位用户 ID。我们鼓励您通过访问 www.facebook.com/r.php?force_64bit 来测试您的应用程序并创建具有 64 位 UID 的测试帐户.”

Edit: Facebook usernames is not the same thing as the user id. The username is of course varchar but will not be returned as the id.

编辑:Facebook 用户名与用户 ID 不同。用户名当然是 varchar,但不会作为 id 返回。

回答by Rich S

Although unlikely, facebook could change the format of their ID's, so to make it future proof, I'd use a varchar.

尽管不太可能,但 facebook 可以更改其 ID 的格式,因此为了将来证明,我将使用 varchar。

回答by Hoff

similar question to: Facebook user_id : big_int, int or string?

类似的问题:Facebook user_id : big_int, int or string?

"I would not use a string. That makes comparisons painful and your indexes clunkier than they need to be."

“我不会使用字符串。这会让比较变得痛苦,而且你的索引比他们需要的更笨拙。”

回答by FuzzyAmi

To quote facebook's upgrade notes regarding graph API v2.0 (effective May 2015):

引用 facebook 关于图形 API v2.0 的升级说明(2015 年 5 月生效):

All IDs are strings. In v1.0, IDs were often large numbers.

所有的 ID 都是字符串。在 v1.0 中,ID 通常是大数字。

Which (to me) implies that userids are not guaranteed to be numbers. In fact, facebook recommend that you use strings:

这(对我而言)意味着不能保证用户 ID 是数字。事实上,facebook 建议你使用字符串:

https://developers.facebook.com/docs/graph-api/reference/v2.2/user#fields

https://developers.facebook.com/docs/graph-api/reference/v2.2/user#fields

Name:id
Description: id The id of this person's user account.

This ID is unique to each app and cannot be used across different apps(...)

type: string

名称:id
描述:id 此人的用户帐户的 id。

此 ID 对每个应用程序都是唯一的,不能在不同的应用程序之间使用(...)

类型:字符串

Although I must admit I've never seen an alphanumeric id.

尽管我必须承认我从未见过字母数字 ID。

回答by Faizan Noor

Use BIGINT(64) to store Facebook User IDs.
Here you go: https://developers.facebook.com/blog/post/45/

使用 BIGINT(64) 存储 Facebook 用户 ID。
给你:https: //developers.facebook.com/blog/post/45/

回答by Eddy Chan

For new data types, as they are grahp obj ID, I believe it is safe to save them as BINT. However, for old "id", e.g. pic, save them as string (you can easily see that they are in the format xxxxxx_xxxxxxxx)

对于新的数据类型,因为它们是 grahp obj ID,我相信将它们保存为 BINT 是安全的。但是,对于旧的“id”,例如 pic,将它们保存为字符串(您可以很容易地看到它们的格式为 xxxxxx_xxxxxxxx)

回答by genesis

I'd use INT, because it's not so big. Searching in INT is faster and betterfor ordering

我会使用 INT,因为它不是那么大。在 INT 中搜索更快更好地进行排序