Whatever message this page gives is out now! Go check it out!
Mode | Syntax |
Creating the service | new http() or createObject("component","http") |
Initializing the attributes | Any one of the following:
|
Executing the service action | httpService.send(_attribute-value_pair_) |
<cfhttp name="onerow"> |
httpService.setName("onerow"); |
Description | Used to add cfhttpparam tags. For example, to specify http POST operations in CFScript. Specifies parameters to build an HTTP request. |
Syntax | httpService.addParam(attribute-value pair) |
Returns | Nothing |
Arguments | All attributes supported by cfhttpparam tag can be used as attribute-value pairs. |
Description | Used to generate an HTTP request and handle the response from the server. |
Returns | A component on which the following methods can be invoked: |
Syntax | httpService.send(attribute_value pair) |
Arguments | All attributes supported by the cfhttpparam tag. |
Description | Sets attributes for the http function. |
Returns | Nothing |
Syntax | httpService.setAttributes (attribute-value pair) |
Arguments | All arguments supported by the cfhttp tag. |
Description | Gets attributes that were set for the http function. |
Returns | Returns a struct with all or some of the service tag attribute values. |
Syntax | httpService.get_Attributes_(attribute_list) |
Arguments | A comma-separated list of attributes. If no list is specified, all defined attributes are returned. |
Description | Removes all attributes added for the http function. |
Returns | Nothing |
Syntax | httpService.clearAttributes(attribute_list) |
Arguments | A comma-separated list of attributes. |
Description | Removes cfhttpparam tags that were added using the addParam method. |
Returns | Nothing |
Syntax | httpService.clearParams() |
Arguments | None |
Description | Removes all attributes and cfhttpparam tags that were added using the addParam method. |
Returns | Nothing |
Syntax | httpService.clear() |
Arguments | None |
<!---
<cfset videoName = "<video path>\hello.wmv">
<cfset videoFileName = "hello.wmv">
--->
<!--- Set User Account Data --->
<!---
<cfset clientKey = "enter client key from google"/>
<cfset devKey = "ebtdev key from google>"/>
--->
<cfscript>
/* youtube uplaod url */
youTubeUploadURL = "http://uploads.gdata.youtube.com/feeds/api/users/default/uploads";
/* video to upload */
videoName = ExpandPath('./hello.wmv');
videoFileName = "hello.wmv";
/* set user account data */
clientKey = "enter client key from google";
devKey = "ewnter dev key from google";
/* create new http service */
httpService = new http();
/* set attributes using implicit setters */
httpService.setMethod("post");
httpService.setCharset("utf-8");
httpService.setUrl("https://www.google.com/accounts/ClientLogin");
/* add httpparams using addParam() */
httpService.addParam(type="formfield",name="accountType",value="HOSTED_OR
_GOOGLE");
httpService.addParam(type="formfield",name="Email",value="enter gmail id");
httpService.addParam(type="formfield",name="Passwd",value="enter password");
httpService.addParam(type="formfield",name="service",value="youtube");
httpService.addParam(type="formfield",name="source",value="youtubecode");
/* make the http call to the URL using send() */
result = httpService.send().getPrefix();
/* process the filecontent returned */
content = listtoarray(result.filecontent,chr(10));
for(i=1;i lte arraylen(content);i++)
{
item = content[i];
authdata[listFirst(item, "=")] = listRest(item, "=");
}
</cfscript>
<!--- Create ATOM XML and save to a file to be sent with video --->
<cfsavecontent variable="meta">
<cfoutput>
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:media="http://search.yahoo.com/mrss/"
xmlns:yt="http://gdata.youtube.com/schemas/2007">
<media:group>
<media:title type="plain">WithOutQuotes</media:title>
<media:description type="plain">Test Description</media:description>
<media:category
scheme="http://gdata.youtube.com/schemas/2007/categories.cat">People
</media:category>
<media:keywords>yourvideo</media:keywords>
</media:group>
</entry>
</cfoutput>
</cfsavecontent>
<cfscript>
tmpfile = expandPath("./meta.xml");
FileWrite(tmpfile,trim(meta));
/* use the httpService created above */
httpService.setUrl("http://uploads.gdata.youtube.com/feeds/api/users/default/
uploads");
httpService.setTimeOut(450);
httpService.setMultipartType("related");
/* clear params first */
httpService.clearParams();
/* add httpparams using addParam() */
httpService.addParam(type="header",name="Authorization", value="GoogleLogin auth=#authdata.auth#");
httpService.addParam(type="header",name="X-GData-Client", value="#variables.clientkey#");
httpService.addParam(type="header",name="X-GData-Key", value="key=#variables.devkey#");
httpService.addParam(type="header",name="Slug",value="#videoFileName#");
httpService.addParam(type="file",name="API_XML_Request",file="#tmpfile#",
mimetype=
"application/atom+xml");
httpService.addParam(type="file",name="file",file="#videoName#",mimetype
="video/*");
/* make the http call to the URL using send() */
result = httpService.send().getPrefix();
if(result.statuscode contains "201")
{
WriteOutput("Your video has been successfully uploaded to YouTube");
}
else
{
WriteOutput("There was a problem uploading the video. Status code returned was " & result.statuscode);
}
</cfscript>