Update twitter status without prompting user using pure JavaScript - javascript

I have web application where people can login from twitter and based on their preference and DOM events I need update their status on twitter. I have a good idea how to do this on server side, but for this project I am not using any server side code, So how can I do this by just javascript, #anywhere twitter api and twitter intents are taking me to no where because they prompt user for submitting the tweet which I dont want.

A pure Javascript solution to consume twitter API is not possible without compromising your consumer secret key. Twitter API authenticates every request using a HMAC-SHA1 token, the SHA1 token is generated using the public/private key assigned by twitter to your api account. If you plan to generate this token using a pure javascript SHA1 implementation then it means you will be exposing your private key in the javascript code which anyone can look at.
Even though technically its possible (provided you can find a javascript library which implements SHA1), its not advisable.
FYI, jQuery.Ajax method does let you modify the headers of the ajax request by tapping in to the beforeSend(jqXHR, settings) method.

You should be able to do this with an AJAX POST request to the REST API. Documentation: https://dev.twitter.com/docs/api/1/post/statuses/update
You target the URL http://api.twitter.com/1/statuses/update.format, where format can be either xml or json, and reflects the format of the response. Required data is the status text, and there are several optional parameters which I won't list here. This only works for the currently authenticated user.
An (untested) example using jQuery:
var message = "This is a tweet, there are many like it but this one is mine";
$.ajax({
type: "POST",
url: "http://api.twitter.com/1/statuses/update.json",
data: "status="+message,
datatype: "json"
});

Related

Unable to post comment on linkedin via API

I want to post "comment" on linkedin post(dynamic),I am using following url but i dont know which information should be pass for post comment on linkedin post ? How can i do this ?
I tried with following url
POST https://api.linkedin.com/rest/socialActions/{shareUrn|ugcPostUrn|commentUrn}/comments
You can find a description of the required URL parameters, and the expected request body, and a sample in the documentation here: https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/comments-api?view=li-lms-2022-12&tabs=http#create-a-comment
When you click the "curl" tab of the sample, you'll also see the HTTP headers.
Since you tagged this as PHP, you'll first want to create an array representing the POST body and encode that with JSON. You can then use the builtin curl support or via a package like GuzzleHTTP to send the actual POST request. Alternatively, there are free and open-source packages that implement easy-to-use wrappers around the LinkedIn API for use in PHP.

sending data to URL from FB - ZAPIER

I'm trying to send data out of zapier on FB lead fetch.
is there anyway to do it?
or i must use external php file first?
i need to get name, email and send it to CRM (which is not listed in zapier) my CRM can use URL or XML input. No normal JS API.
Thanks
Zapier has webhooks that let you send data out. Your CRM is then responsible for processing that data (converting it to the right format, etc). You could also add your CRM as a Zapier app that can accept data from your trigger source and perform necessary API calls, updates, etc.
I found
fetch('http://clients.frontask.co.il/WebToLead.aspx&type=get&FirstName='+input.name+'&Email='+input.email+'&Phone='+input.phone+'&lead_from='+input.lead+'&SystemID=UpdateExistingDetails=[1]', { method: 'GET' }).then(function(res) {return res.text();}).then(function(body) {var output = {id: 1234, rawHTML: body};callback(null, output);}).catch(callback);
do the job, but i faced another problem.
because of the system restrictions i cannot use url, i need to send XML file.
Any change I can do it?
thanks

How to access web service from Javascript or PHP?

I want to access a web service from here in my web application. When the user chooses a species name, the service will inform if the name is valid, the author and year of the name, etc.
First I thought of using Javascript, since the information comes from the user. Then I saw cross-domain restrictions, so I wonder what is the best workaround here. According to this suggestion, I should be using a server-side workaround. But in that case, wouldn't it be easier to just use php curl functions?
Yes.
If you want to do this reliably, do it from a computer you control.
If you are using PHP already, than cURL is the usual HTTP client library.
That said, using PHP/cURL on your server is the server side workaround to cross-origin JS issues, not an alternative to using a workaround.
Try this ajax code.
$.ajax({
url: 'http://localhost/webservice.php?callback=',
type: "GET/POST",
data:{data:JSON.stringify([{action:'getUserData', userId: 1234}])},
dataType: "jsonp",
crossdomain: true
});
For more details refer this link HTML-PHP Webservice using the AJAX with crossDomain as TRUE.

How do I access Wolfram's API data?

Could someone explain how I can access Wolfram's API data? I'm not worried about formatting for now--I would just like to learn the basics of interacting with the API.
The Wolfram website FAQ says this: "The Wolfram|Alpha API is designed to operate with interactive web technologies such as AJAX, Flash, and Silverlight."
And the documentation, which is located here: http://products.wolframalpha.com/api/documentation.html, says this: "A simple API call to retrieve output for the query "pi" would look like this:
http://api.wolframalpha.com/v2/query?input=pi&appid=XXXX
This query did not specify a desired output format, and the default is to retrieve the plaintext and image representations of each subpod. The image is returned as an <img> tag suitable for direct inclusion in a web page. Here is the output:"
I just have no idea how to put this together to actually access the Wolfram API data. Do I use AJAX or something else? What is the basic code for accessing the data?
I'm very new at this, so any help would be greatly appreciated. Thanks a lot!!
To use XMLHttpRequest their server must enable credentials by setting the Access-Control-Allow-Credentials response header to “true”
https://en.wikipedia.org/wiki/Cross-origin_resource_sharing
By AJAX I think they mean your server code should make the request.
In the next example they use Java Server Pages on their own domain to make the request:
https://reference.wolfram.com/webMathematica/tutorial/ApplicationsAJAX.html
Check other answers:
Wolfram API javascript cross origin sharing issue
If you use JQuery, a common javasSript framework, you can make an ajax request as follows
var requestData = function() {
$.ajax({
url: "http://api.wolframalpha.com/v2/query?input=pi&appid=XXXX",
}).done(function(data) {
//data should contain the response from wolframalpha
});

Send HTTP Basic-Auth header info while submitting pdf to webserver

I'm looking for a sample as to how to send HTTP Basic-Auth header info as part of pdf submit via javascript.
I found the following sample javascript code from one of the iText pdf examples:
this.submitForm({
cURL:"http://itextpdf.com:8080/book/request",
cSubmitAs: "HTML"
});
Are there any other options to send HTTP username:password as part of the submitForm() method?
Thanks for your help.
I'm not an expert on using forms with PDFs, but from what I gather from the API documentation (page 345) and the responses on Adobe's help forum it doesn't look possible.
You may take a look into Net.HTTP.request though, that one does have an oAuthenticate argument (page 550 on the API 8.1 documentation or here for API 9.1) that would allow you to pass user and password for HTTP authentication or show a dialog where the user can type those in -- you can actually modify any HTTP header.
Performing a POST request that way with an appropriate oRequest would (probably) end up having the result you are looking for.
Note: Just realised the PDF I was citing is from SDK 8.1, SDK 9.1 doesn't show any authentication parameter for the submitForm method either though.

Categories