I’m using OAuth to authenticate my app to access a user’s facebook details using OAuth. Recently, I migrated the database to use PostgreSQL, and now am having trouble storing the token information when returned from Facebook.
The exact error is:
PG::Error: ERROR: invalid input syntax for type timestamp: "1350424800"
: INSERT INTO "authentications" ("created_at", "oauth_expires_at", "oauth_token", "provider", "uid", "updated_at", "user_id") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id"
Strangely, this wasn’t the case with SQLite, so it’s clearly something to do with the format in which Facebook returns the expiry date (“1350424800”). Any thoughts on how I should parse this to make it work?
I’m not doing anything clever with the way it’s created at present, simply:
def self.create_with_omniauth(auth)
create(uid: auth['uid'], provider: auth['provider'], oauth_token: auth['credentials'].token, oauth_expires_at: auth['credentials'].expires_at)
end
Any help greatly appreciated!
You have a nummeric Unix Timestamp value here – whereas the PostgreSQL data type
timestampobviously has to be given in another format.And looking here http://www.postgresql.org/docs/current/static/datatype-datetime.html#DATATYPE-DATETIME-DATE-TABLE, you can see some of the accepted formats, but a nummeric Unix Timestamp does not appear to be listed there.
So you’ll have to convert/format the value into one of the accepted formats first; there might be a function designed to do this in PostgreSQL … (if not, Google should help).