|
24 | 24 | MINTLIFY_CONFIG = { |
25 | 25 | "outputDir": "mintlify-docs", |
26 | 26 | "baseUrl": "https://docs.x.com", |
27 | | - "title": "X API SDK v0.2.7-beta", |
| 27 | + "title": "X API SDK v0.3.0", |
28 | 28 | "description": "Python SDK for the X API with comprehensive pagination, authentication, and streaming support.", |
29 | | - "version": "0.2.7-beta", |
| 29 | + "version": "0.3.0", |
30 | 30 | "githubUrl": "https://github.com/xdevplatform/xdk", |
31 | 31 | } |
32 | 32 |
|
@@ -1270,36 +1270,40 @@ def process_docs(): |
1270 | 1270 | 3. Initiate the flow, direct user to auth URL and handle callback. |
1271 | 1271 | **Example** (using a web server for callback): |
1272 | 1272 | ```python |
1273 | | -from xdk.auth import OAuth2PKCE |
| 1273 | +from xdk.oauth2_auth import OAuth2PKCEAuth |
1274 | 1274 | from urllib.parse import urlparse |
1275 | 1275 | import webbrowser |
1276 | 1276 | # Step 1: Create PKCE instance |
1277 | | -auth = OAuth2PKCE( |
1278 | | - client_id="your_client_id", |
1279 | | - redirect_uri="http://localhost:8080/callback", |
1280 | | - scopes=["tweet.read", "users.read", "offline.access"] # Adjust scopes as needed |
| 1277 | +auth = OAuth2PKCEAuth( |
| 1278 | + client_id="YOUR_CLIENT_ID", |
| 1279 | + redirect_uri="YOUR_CALLBACK_URL", |
| 1280 | + scope="tweet.read users.read offline.access" |
1281 | 1281 | ) |
1282 | 1282 | # Step 2: Get authorization URL |
1283 | | -auth_url = auth.get_authorization_url() |
| 1283 | +auth_url, state = auth.get_authorization_url() |
1284 | 1284 | print(f"Visit this URL to authorize: {auth_url}") |
1285 | 1285 | webbrowser.open(auth_url) |
1286 | 1286 | # Step 3: Handle callback (in a real app, use a web framework like Flask) |
1287 | 1287 | # Assume callback_url = "http://localhost:8080/callback?code=AUTH_CODE_HERE" |
1288 | 1288 | callback_url = input("Paste the full callback URL here: ") |
1289 | | -parsed = urlparse(callback_url) |
1290 | | -code = parsed.query.split("=")[1] |
1291 | 1289 | # Step 4: Exchange code for tokens |
1292 | | -tokens = auth.fetch_token(authorization_code=code) |
| 1290 | +tokens = auth.fetch_token(authorization_response=callback_url) |
1293 | 1291 | access_token = tokens["access_token"] |
1294 | 1292 | refresh_token = tokens["refresh_token"] # Store for renewal |
1295 | 1293 | # Step 5: Create client |
1296 | | -client = Client(oauth2_access_token=access_token) |
| 1294 | +# Option 1: Use bearer_token (OAuth2 access tokens work as bearer tokens) |
| 1295 | +client = Client(bearer_token=access_token) |
| 1296 | +# Option 2: Pass the full token dict for automatic refresh support |
| 1297 | +# client = Client(token=tokens) |
1297 | 1298 | ``` |
1298 | 1299 | **Token Refresh** (automatic in SDK for long-lived sessions): |
1299 | 1300 | ```python |
1300 | 1301 | # If access token expires, refresh using stored refresh_token |
1301 | | -tokens = auth.refresh_token(refresh_token=refresh_token) |
1302 | | -client = Client(oauth2_access_token=tokens["access_token"]) |
| 1302 | +# The refresh_token method uses the stored token from the OAuth2PKCEAuth instance |
| 1303 | +tokens = auth.refresh_token() |
| 1304 | +# Use the refreshed token |
| 1305 | +client = Client(bearer_token=tokens["access_token"]) |
| 1306 | +# Or pass the full token dict: client = Client(token=tokens) |
1303 | 1307 | ``` |
1304 | 1308 | ### 3. OAuth 1.0a User Context |
1305 | 1309 | For legacy endpoints that require OAuth 1.0 support. |
|
0 commit comments