I have a requirement to update twitter status with media . I am using following Twitter API for it.
https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media.
Doing this with nodejs twit library "https://github.com/ttezel/twit"
twit = new Twit({
consumer_key: TWITTER_OAUTH_KEY
, consumer_secret: TWITTER_OAUTH_SECRET
, access_token: 'access token'
, access_token_secret: 'secret'
});
wallpost = {};
wallpost.status = 'media upload1 deliverdfd\nhttp://www.animalplanet.com/';
wallpost.media = [{
"media_url": "http:\/\/pbs.twimg.com\/media\/A7EiDWcCYAAZT1D.jpg",
"media_url_https": "https:\/\/pbs.twimg.com\/media\/A7EiDWcCYAAZT1D.jpg",
"url": "http:\/\/t.co\/bAJE6Vom",
"display_url": "pic.twitter.com\/bAJE6Vom",
"expanded_url": "http:\/\/twitter.com\/BarackObama\/status\/266031293945503744\/photo\/1",
"type": "photo",
}];
My post request
twit.post( "update_with_media", wallpost, function(err, res2) {
if (err) {
return next(err);
}
console.info(res2);
// returns the post id
res.json({
status: 200,
info: "OK",
id: res2.id
});
});
Am getting an error message [{"code":195,"message":"Missing or invalid url parameter"}]}.
I have googled it found some threads some of them mentioning about set content type multipar form data. But i don't know how to set content type.
I have tried
var multipart = [{
"Content-Type": "multipart/form-data"
}];
wallpost.content_type = multipart;
not working for me. Please help me to solve this issue. Thank you
From the documentation you linked to
Supported image formats are PNG, JPG and GIF, including animated GIFs of up to 3MB . This data must be either the raw image bytes or encoded as base64.
You can only upload images - not links to images. Save an image locally and add it to media as a base64 encoded string.
You can not send links - even to Twitter images.
Related
As per microsoft graph API documentation the createUploadSession graph API only return the URL where attachment can upload but how to upload attachment chunk by chunk in javascript? does anyone knows? Thanks in advance.
I'm referring this reference
Here is the reference for attaching the Attachment to a post in JavaScript, Please refer this Document
const options = {
authProvider,
};
const client = Client.init(options);
const reply = {
post: {
body: {
contentType: 'text',
content: 'Which quarter does that file cover? See my attachment.'
},
attachments: [{
'#odata.type': '#microsoft.graph.fileAttachment',
name: 'Another file as attachment',
contentBytes: 'VGhpcyBpcyBhIGZpbGUgdG8gYmUgYXR0YWNoZWQu'
} ]
}
};
await client.api('/groups/1848753d-185d-4c08-a4e4-6ee40521d115/threads/AAQkADJUdfolA==/reply')
.post(reply);
Hope this helpful.
I visited the Youtube Data v3 API docs to know about how to upload videos using the client library
I got to this page
https://developers.google.com/youtube/v3/docs/videos/insert
but it doesn't seem to explain where to put the video in the request
And Also API explorer just gives the code for request, it doesn't let me execute the code for that page
I also read the resource structure page but didn't find where to put the video
https://developers.google.com/youtube/v3/docs/videos#resource
here's my current code
let req = gapi.client.youtube.videos.insert({
part: 'snippet,status',
snippet: {
title: "Test Video",
description: "Test Description",
categoryId: 28,
defaultLanguage: 'en',
defaultAudioLanguage: 'en'
},
status: {
privacyStatus: "private"
},
});
console.log(req)
try {
req.execute(function (response) {
console.log(response);
});
} catch (e) {
console.error(e);
}
Now, where do I put the video in the request?
do I have to put that as buffer?
I am fetching video from fetch API for uploading via API
and whenever I run the code I get the Error: 400 in the console
code: 400
data: [{…}]
error: {code: 400, data: Array(1), message: 'Request contains an invalid argument.'}
message: "Request contains an invalid argument."
so can you provide a working example of uploading a video using the client library that is fetched from the fetch API
and show to structure the request body when using the client library?
This is the request body I'm using. Code below was taken from this sample script: https://quanticdev.com/articles/automating-my-youtube-uploads-using-nodejs/
In my case I'm uploading an .mp4
auth: auth,
part: 'snippet,status',
requestBody: {
snippet: {
title,
description,
tags,
categoryId: 20,
defaultLanguage: 'en',
defaultAudioLanguage: 'en'
},
status: {
privacyStatus: "public",
selfDeclaredMadeForKids: false
},
},
media: {
body: fs.createReadStream(videoPath),
}
I am trying to send a FormData object from my React Native app to my Rails API.
I am using react-native-image-crop-picker to pick the image from gallery and store the image object in my state:
ImagePicker.openPicker({
multiple: true,
cropping: true,
includeBase64: true,
compressImageMaxHeight: 1080,
compressImageMaxWidth: 1080,
})
.then(selectedImages => {
selectedImages.map(image => {
let prefix;
let ext;
[prefix, ext] = image.filename.split(".");
ext = ext.toLowerCase() === "heic" ? "jpg" : ext;
const upload = {
uri: image.path,
type: image.mime,
name: `${prefix}.${ext}`,
};
this.setState(prevState => ({
event: {
...prevState.event,
images: [...prevState.event.images, upload],
},
}));
});
})
.catch(error => {
});
Then i create a FormData object to send yo my Rails API:
const data = new FormData();
data.append("name", event.name);
data.append("description", event.description);
data.append("date", event.date);
data.append("time", event.time);
data.append("images", event.images[0]);
My api successfully receives que request:
Parameters: {"event"=>{"_parts"=>[["event[name]", ""], ["event[description]", ""], ["event[date]", ""], ["event[time]", ""], ["event[images]", {"uri"=>"/private/var/mobile/Containers/Data/Application/6226B812-CDEC-4994-A864-0A91EE8C44B3/tmp/react-native-image-crop-picker/BFC043EC-D33F-4E07-BBEA-634CE5DE8A3F.jpg", "type"=>"image/jpeg", "name"=>"IMG_7142.jpg"}]]}}
Now, how can i recover this image and saves directly in my Rails ActiveStorage?
I am trying to directly attach the image object: {"uri"=>"/private/var/mobile/Containers/Data/Application/6226B812-CDEC-4994-A864-0A91EE8C44B3/tmp/react-native-image-crop-picker/BFC043EC-D33F-4E07-BBEA-634CE5DE8A3F.jpg", "type"=>"image/jpeg", "name"=>"IMG_7142.jpg"} to my model, but i am getting the current exception: ActiveRecord::RecordNotSaved (Failed to save the new associated avatar_attachment.):
I see that you have multiple images to attach.
If you've already gone through the documentation, I believe you must have already setup active storage by now.
In your model do you have has_many_attached :images? note that images could've been something else or just about any name.
I was able to retrieve the image name by doing the following (but I doubt if it will work for your purpose):
hash = {"uri"=>"/private/var/mobile/Containers/Data/Application/6226B812-CDEC-4994-A864-0A91EE8C44B3/tmp/react-native-image-crop-picker/BFC043EC-D33F-4E07-BBEA-634CE5DE8A3F.jpg", "type"=>"image/jpeg", "name"=>"IMG_7142.jpg"}
hash['uri'].split('/')[-1]
=> "BFC043EC-D33F-4E07-BBEA-634CE5DE8A3F.jpg"
If the above route is how you want to go and you are sure that it will work this way, then you need to do something like:
#your_model.images.attach(io: File.open("#{hash['uri']}"), filename: "#{hash['uri'].split('/')[-1]}")
You can find here a complete tutorial on how this should actually work here - https://medium.com/#ashley_foster/react-native-image-uploads-with-activestorage-ec4898317a82
Give it a try and if you get stuck along the way, you can drop a comment or edit/update your question.
I am using npm-twit in node.js to get tweets with the twitter search api.
I am totally new to programming but need it for my master thesis. I therefore got the premium account with full archive access to the search requests.
With the standard free api access my code worked without any problems. But now I do not know how to correctly implement access tokens etc.
I tried putting product and label in different places and changed q to query and data.statues to data.results but anything I tried gives me several error codes - like
'code: 195, message: 'Missing or invalid url parameter.'
'code: 25, message: 'Query parameters are missing.'
'message: 'Sorry, that page does not exist', code: 34'.
Or tells me that tweets.length does not exist (even though it worked before).
Or a simple 'null'
(when I use this code snipped :
T.get('search/tweets/fullarchive/:dev', params , gotData); function gotData(err, data, response){console.log(data)}
)
//This is the current code which is not working
var Twit = require('twit');
var config = require('./config');
var T = new Twit({
consumer_key: 'XXX',
consumer_secret: 'XXX',
access_token: 'XXX',
access_token_secret: 'XXX',
timeout_ms: 60*1000,
strictSSL: true,
app_only_auth: true,
PRODUCT: 'fullarchive',
LABEL: 'dev',});
var params = {
query: 'VW',
fromDate:'201801010000',
toDate:'201901010000',
followers_count:1000,
maxResults: 500,
result_type: 'popular',
lang: 'en'
//next: ''
}
T.get('search/tweets/fullarchive/:dev', params , gotData);
//T.get('search/tweets', params , gotData); - gives me all results in standard api
function gotData(err, data, response)
{
var tweets = data.results; //var tweets = data.statuses - gives me what I need in standard api
for (var i = 0; i < tweets.length; i++)
console.log(tweets[i].text, tweets[i].retweet_count,tweets[i].created_at,tweets[i].id_str,tweets[i].favorite_count,);
With this code I get an error 'Unhandled rejection TypeError: Cannot read property 'results' of null'
Ideally I want to get information about the tweet containing its text, creation date, retweet count, tweet id, favorite count - and if possible the "next" token when needed.
I would really appreciate any help!
I am getting this error while we are uploading image to facebook.And i am given the permissions.
https://graph.facebook.com/me/photos
{
"error": {
"message": "An active access token must be used to query information about the current user.",
"type": "OAuthException",
"code": 2500
}
}
This is my as3
var params:Object = {image:img, message:'vcxv', fileName:'vcxvc',name: 'My Card'};
Facebook.api('/me/photos', onSaveToPhotoAlbumComplete, params, "POST");
Please help me.
You have to add an Access Token to Object:
access_token:Facebook.getAuthResponse().accessToken
var params:Object = {image:img, message:'vcxv', fileName:'vcxvc',name: 'My Card', access_token:Facebook.getAuthResponse().accessToken};
Facebook.api('/me/photos', onSaveToPhotoAlbumComplete, params, "POST");