providers/twitter
TwitterProfile
可索引
[claims
: string
]: unknown
屬性
data
data: {
created_at: string;
description: string;
email: string;
entities: {
description: {
hashtags: {
end: number;
start: number;
tag: string;
}[];
};
url: {
urls: {
display_url: string;
end: number;
expanded_url: string;
start: number;
url: string;
}[];
};
};
id: string;
location: string;
name: string;
pinned_tweet_id: string;
profile_image_url: string;
protected: boolean;
url: string;
username: string;
verified: boolean;
};
created_at?
optional created_at: string;
description?
optional description: string;
此使用者個人資料描述(也稱為簡介)的文字,如果使用者有提供的話。
若要傳回此欄位,請在授權請求的查詢參數中加入 user.fields=description
。
email?
optional email: string;
注意
Twitter 目前不支援電子郵件。
entities?
optional entities: {
description: {
hashtags: {
end: number;
start: number;
tag: string;
}[];
};
url: {
urls: {
display_url: string;
end: number;
expanded_url: string;
start: number;
url: string;
}[];
};
};
此物件及其子欄位包含使用者描述中具有特殊含義的文字的詳細資訊。
若要傳回此欄位,請在授權請求的查詢參數中加入 user.fields=entities
。
entities.description
description: {
hashtags: {
end: number;
start: number;
tag: string;
}[];
};
包含使用者描述中 URL、主題標籤、現金標籤或提及的詳細資訊。
entities.description.hashtags
hashtags: {
end: number;
start: number;
tag: string;
}[];
entities.url
url: {
urls: {
display_url: string;
end: number;
expanded_url: string;
start: number;
url: string;
}[];
};
包含使用者個人資料網站的詳細資訊。
entities.url.urls
urls: {
display_url: string;
end: number;
expanded_url: string;
start: number;
url: string;
}[];
包含使用者個人資料網站的詳細資訊。
id
id: string;
此使用者的唯一識別碼。為避免語言和工具無法處理大型整數的問題,此識別碼以字串形式傳回。
location?
optional location: string;
使用者個人資料中指定的位置(如果使用者有提供)。由於這是一個自由格式的值,因此它可能未指示有效位置,但使用位置查詢執行搜尋時可能會進行模糊評估。
若要傳回此欄位,請在授權請求的查詢參數中加入 user.fields=location
。
name
name: string;
此使用者的友善名稱,如其個人資料中顯示。
pinned_tweet_id?
optional pinned_tweet_id: string;
此使用者釘選推文的唯一識別碼。
您可以透過在授權請求的查詢參數中加入 expansions=pinned_tweet_id
,在 includes.tweets
中取得展開的物件。
profile_image_url?
optional profile_image_url: string;
此使用者的個人資料圖片 URL,如使用者個人資料中顯示。
protected?
optional protected: boolean;
url?
optional url: string;
使用者個人資料中指定的 URL(如果存在)。
若要傳回此欄位,請在授權請求的查詢參數中加入 user.fields=url
。
username
username: string;
此使用者的 Twitter 帳號(螢幕名稱)。
verified?
optional verified: boolean;
指示此使用者是否為已驗證的 Twitter 使用者。
若要傳回此欄位,請在授權請求的查詢參數中加入 user.fields=verified
。
includes?
optional includes: {
tweets: {
id: string;
text: string;
}[];
};
tweets?
optional tweets: {
id: string;
text: string;
}[];
default()
default(config): OAuthConfig<TwitterProfile>
將 Twitter 登入新增至您的頁面。
設定
回調網址
https://example.com/api/auth/callback/twitter
設定
import { Auth } from "@auth/core"
import Twitter from "@auth/core/providers/twitter"
const request = new Request(origin)
const response = await Auth(request, {
providers: [
Twitter({
clientId: TWITTER_CLIENT_ID,
clientSecret: TWITTER_CLIENT_SECRET,
}),
],
})
資源
OAuth 2
Twitter 支援 OAuth 2,目前為選擇性加入。若要啟用它,只需在您的提供者設定中加入 version: “2.0” 即可
Twitter({
clientId: process.env.TWITTER_ID,
clientSecret: process.env.TWITTER_SECRET,
version: "2.0", // opt-in to Twitter OAuth 2.0
})
請注意,雖然這個變更很簡單,但它會改變您與 Twitter API 互動的方式以及使用的 API。請閱讀官方 Twitter OAuth 2 文件以取得更多詳細資訊。
Twitter OAuth 2.0 目前不支援電子郵件。
注意事項
Twitter 目前是唯一使用 OAuth 1.0 規範的內建提供者。這意味著您不會收到 access_token
或 refresh_token
,而是分別收到 oauth_token
和 oauth_token_secret
。如果您正在使用轉接器 (Adapter),請記得將它們加入您的資料庫綱要中。
如果您想取得使用者的電子郵件地址,您必須在應用程式權限中啟用「向使用者請求電子郵件地址」選項。
預設情況下,Auth.js 假設 Twitter 提供者是基於 OAuth 2 規範。
Twitter 提供者帶有預設設定。若要覆寫您的使用案例的預設值,請查看自訂內建 OAuth 提供者。
參數
參數 | 類型 |
---|---|
config | OAuthUserConfig <TwitterProfile > |