Add handle of the logged-in user to API
This commit is contained in:
parent
6302b3d5ab
commit
c3494cfe19
@ -17,9 +17,9 @@ const API_CONVERSATION_BASE_PATH = "https://twitter.com/i/api/2/timeline/convers
|
||||
const API_USER_TIMELINE_BASE_PATH = "https://api.twitter.com/2/timeline/profile/"
|
||||
|
||||
type API struct {
|
||||
UserHandle UserHandle
|
||||
IsAuthenticated bool
|
||||
GuestToken string
|
||||
AuthenticationToken string
|
||||
Client http.Client
|
||||
CSRFToken string
|
||||
}
|
||||
@ -56,7 +56,6 @@ func NewGuestSession() API {
|
||||
return API{
|
||||
IsAuthenticated: false,
|
||||
GuestToken: guestAPIString,
|
||||
AuthenticationToken: "",
|
||||
Client: http.Client{
|
||||
Timeout: 10 * time.Second,
|
||||
Jar: jar,
|
||||
@ -108,6 +107,28 @@ func (api *API) LogIn(username string, password string) {
|
||||
}
|
||||
}
|
||||
|
||||
type final_result_struct struct {
|
||||
Subtasks []struct {
|
||||
OpenAccount struct {
|
||||
User struct {
|
||||
Name string
|
||||
ScreenName string `json:"screen_name"`
|
||||
}
|
||||
} `json:"open_account"`
|
||||
}
|
||||
}
|
||||
bytes, err := json.Marshal(result)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var final_result final_result_struct
|
||||
err = json.Unmarshal(bytes, &final_result)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
api.UserHandle = UserHandle(final_result.Subtasks[0].OpenAccount.User.ScreenName)
|
||||
|
||||
dummyURL, err := url.Parse(loginURL)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
@ -1,28 +1,30 @@
|
||||
package scraper_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"offline_twitter/scraper"
|
||||
. "offline_twitter/scraper"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestAuthentication(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
|
||||
username := "offline_twatter"
|
||||
password := "S1pKIW#eRT016iA@OFcK"
|
||||
|
||||
api := scraper.NewGuestSession()
|
||||
api := NewGuestSession()
|
||||
api.LogIn(username, password)
|
||||
|
||||
assert.True(api.IsAuthenticated)
|
||||
assert.NotEqual(api.CSRFToken, "")
|
||||
assert.Equal(api.UserHandle, UserHandle("Offline_Twatter"))
|
||||
|
||||
response, err := api.GetLikesFor(1458284524761075714, "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(response)
|
||||
require.NoError(err)
|
||||
trove, err := response.ToTweetTrove()
|
||||
require.NoError(err)
|
||||
assert.True(len(trove.Tweets) > 0)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user