I’ve created an app in x developer and i got my bearer token, API key, API key secret, access token and access token secret, client id and client secret. However when I execute my code i am getting a 403 forbidden error which twitter says it means
The request is understood, but it has been refused or access is not allowed. An accompanying error message will explain why.Check that your developer account includes access to the endpoint you’re trying to use. You may also need to get your App allowlisted (e.g. Engagement API or Ads API) or sign up for access.”.
I have the free access on x developer
this is my code:
aspx:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="twitter_trends.aspx.vb" Inherits="twitter_trends" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Twitter Trends</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Top 10 Twitter Trends</h1>
<asp:Repeater ID="rptTrends" runat="server">
<ItemTemplate>
<p><strong><%# Eval("trend_name") %></strong> - Tweets: <%# Eval("tweet_count") %></p>
</ItemTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
vb:
Imports System.Net
Imports System.IO
Imports System.Web.Script.Serialization
Partial Class twitter_trends
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' Ensure your application uses TLS 1.2 or higher
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
' Call the function to get the trends
Dim trends As String = GetTwitterTrends()
' Display the result (or handle it appropriately)
Response.Write(trends)
End Sub
Private Function GetTwitterTrends() As String
' Replace with your actual bearer token and WOEID
Dim bearerToken As String = "AAAAAAAAAAAAAAAAAAAAAMnKvwEAAAAAimlqPsahop8IlT95p1flZ8eI818%3DDKparMoGqpc31rlBg07SsPmw2soeXqBcH325SYsqxi5FAhjkBv"
Dim woeid As String = "1" ' Use 1 for global trends or specify a location
' Create the request
Dim url As String = "https://api.twitter.com/1.1/trends/place.json?id=" & woeid
Dim request As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
request.Method = "GET"
request.Headers.Add("Authorization", "Bearer " & bearerToken)
request.ContentType = "application/json"
Try
' Get the response
Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
Using reader As New StreamReader(response.GetResponseStream())
Dim jsonResponse As String = reader.ReadToEnd()
Return jsonResponse
End Using
Catch ex As Exception
' Handle any errors
Return "Error: " & ex.Message
End Try
End Function
End Class
can anyone help ?
jouna harb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2