दोनों SDK कई प्रमाणीकरण विधियों का समर्थन करते हैं:
बेयरर टोकन (केवल ऐप)
OAuth 2.0 (उपयोगकर्ता संदर्भ)
OAuth 1.0a (उपयोगकर्ता संदर्भ)
सार्वजनिक डेटा पढ़ने के लिए सबसे आसान विकल्प।Python:
from xdk import Clientclient = Client(bearer_token="YOUR_BEARER_TOKEN")
TypeScript:
import { Client } from '@xdevplatform/xdk';const client = new Client({ bearerToken: 'YOUR_BEARER_TOKEN' });
उपयोगकर्ताओं की ओर से कार्रवाइयों के लिए (पोस्ट करना, फ़ॉलो करना आदि)।Python:
from xdk import Clientfrom xdk.oauth2_auth import OAuth2PKCEAuthauth = OAuth2PKCEAuth( client_id="YOUR_CLIENT_ID", redirect_uri="YOUR_CALLBACK_URL", scope="tweet.read users.read offline.access")# प्राधिकरण URL प्राप्त करेंauth_url = auth.get_authorization_url()# उपयोगकर्ता की अनुमति के बाद, code के बदले टोकन प्राप्त करेंtokens = auth.fetch_token(authorization_response=callback_url)client = Client(bearer_token=tokens["access_token"])
TypeScript:
import { Client, OAuth2, generateCodeVerifier, generateCodeChallenge } from '@xdevplatform/xdk';const oauth2 = new OAuth2({ clientId: 'YOUR_CLIENT_ID', clientSecret: 'YOUR_CLIENT_SECRET', redirectUri: 'https://your-app.com/callback', scope: ['tweet.read', 'users.read', 'offline.access'],});const codeVerifier = generateCodeVerifier();const codeChallenge = await generateCodeChallenge(codeVerifier);oauth2.setPkceParameters(codeVerifier, codeChallenge);const authUrl = await oauth2.getAuthorizationUrl('state');// प्राधिकरण के बाद, code के बदले टोकन प्राप्त करेंconst tokens = await oauth2.exchangeCode(authCode, codeVerifier);const client = new Client({ accessToken: tokens.access_token });
लीगेसी ऐप्लिकेशन या खास उपयोग मामलों के for लिए।Python: