rtweet icon indicating copy to clipboard operation
rtweet copied to clipboard

Modification of profile / profile pic

Open DataStrategist opened this issue 6 years ago • 7 comments

Hi, great package! Thanks so much... captures functionality of multiple packages. 👍

Are you planning to add functionality for a hypothetical post_profile_pic? I'm developing a bot, and one of the outputs is a term coocurrance matrix plot that I'm setting as a profile pic. It would be cool if that constantly changed as the analysis advances. Is that in the cards?

DataStrategist avatar Feb 27 '18 10:02 DataStrategist

I'm keeping this in mind, btw, for the next time I poke around in the post functions. If it's an easy addition, I'll try to add it in the next month or so.

mkearney avatar Mar 24 '18 16:03 mkearney

API endpoint: https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/post-account-update_profile_image

llrs avatar Mar 31 '21 10:03 llrs

From #715: Based on an exchange in Twitter there is interest on changing the banner via the API

Several methods have been tested by @TimTeaFan but currently they don't work. Code can be found on Stack Overflow.

llrs avatar Jun 17 '22 10:06 llrs

So I tested this in a branch profile_banner with the following code:

profile_banner <- function(banner_file, token = NULL) {
  token <- check_token(token)
  banner_uri <- base64enc::base64encode(banner_file)
  r <- TWIT_upload(token,  "/1.1/account/update_profile_banner", 
                 list(image = banner_uri))
  message("your profile banner image has been updated!")
  r
}

Unfortunately the error message I got is 410 which according to this page means they have deactivated the endpoint.

According to the migration map the status is "[Replacement under consideration]".

It is still possible to add a function to retrieve the current profile image if needed, but you could do the same by retrieving the information of a user via search_user() and column profile_banner_url, so I'm not adding support for it now and will wait for API v2 endpoint. I'll leave the issue open as a reminder

llrs avatar Jun 18 '22 22:06 llrs

Thanks for looking into this!

I'm not sure why your error message is 410, but from my experience the Twitter API yields weird and inappropriate error messages especially when the request is not in the correct format.

I'm aware that the user endpoints are on the migration map, however, they are there already for a while and my feeling is, that this is not going to change so fast.

Regarding the possibility that the endpoints are already deactivated, I think that is not the case. Other packages in other languages have no problem with this. Many developers use PHP or node.js, but also the tweepy package in python has support for this endpoint.

In python we can do the following and it will work (I just checked):

import os
import tweepy

# Get environment variables
CONKEY = os.getenv('MYTWITTER_CONSUMER_API_KEY')
CONSEC = os.environ.get('MYTWITTER_CONSUMER_API_SECRET')
ACCKEY = os.getenv('MYTWITTER_ACCESS_TOKEN')
ACCSEC = os.environ.get('MYTWITTER_ACCESS_TOKEN_SECRET')

auth = tweepy.OAuth1UserHandler(
   CONKEY,
   CONSEC,
   ACCKEY,
   ACCSEC
)

api = tweepy.API(auth)

image_url = 'https://raw.githubusercontent.com/TimTeaFan/dynamicTwitterHeader/main/data/test.png'
api.update_profile_banner(image_url)

And this works also for api.udpate_profile.

See here for the documentation of the tweepy package.

TimTeaFan avatar Jun 19 '22 21:06 TimTeaFan

Oh, double checking I found I was uploading it to a different api endpoint, so the 410 makes sense. Fixing that and we are at the same point with the curl error. As you mention on SO the error message is on curl::curl_fetch_memory, there is an open issue (which I just added our experience) there https://github.com/jeroen/curl/issues/232

llrs avatar Jun 19 '22 23:06 llrs

I haven't tested but presumably this should work with this solution: https://github.com/jeroen/curl/issues/232#issuecomment-1231686216

llrs avatar Aug 30 '22 14:08 llrs