Insert into Google Merchant data feed using Content API - ruby-on-rails

I'm trying to insert some data into my merchant account data feed using the Content API. Using the code below, I've been given a "POST requests require a Content-length header. That’s all we know." error, but I've set the content length, so I'm really confused.
One theory I have is that it doesn't know where to put these requests, under my merchant account ID, I have two data feeds, and I'm not sure how to set it to enter into a given data feed.
The XML is stolen from here: https://developers.google.com/shopping-content/batch-operations
#feed = '<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom"
xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/"
xmlns:g="http://base.google.com/ns/1.0"
xmlns:batch="http://schemas.google.com/gdata/batch">
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:sc="http://schemas.google.com/structuredcontent/2009"
xmlns:scp="http://schemas.google.com/structuredcontent/2009/products"
xmlns:app="http://www.w3.org/2007/app">
<batch:operation type="INSERT"/>
<title>Switch 1</title>
<content type="text">A new item available...</content>
<link rel="alternate" type="text/html" href="http://www.example.com/sku123"/>
<sc:id>SKU123</sc:id>
<sc:content_language>en</sc:content_language>
<sc:target_country>US</sc:target_country>
<scp:google_product_category>Electronics > Networking > Hubs &
Switches</scp:google_product_category>
<scp:condition>new</scp:condition>
<scp:price unit="USD">25</scp:price>
<scp:availability>in stock</scp:availability>
</entry>
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:sc="http://schemas.google.com/structuredcontent/2009"
xmlns:scp="http://schemas.google.com/structuredcontent/2009/products"
xmlns:app="http://www.w3.org/2007/app">
<batch:operation type="INSERT"/>
<title>Switch 2</title>
<content type="text">Another item available...</content>
<link rel="alternate" type="text/html" href="http://www.example.com/sku124"/>
<sc:id>SKU124</sc:id>
<sc:content_language>en</sc:content_language>
<sc:target_country>US</sc:target_country>
<scp:google_product_category>Electronics > Networking > Hubs &
Switches</scp:google_product_category>
<scp:condition>new</scp:condition>
<scp:price unit="USD">50</scp:price>
<scp:availability>in stock</scp:availability>
</entry>
</feed>'
http = HTTPClient.new
#output = http.post('https://content.googleapis.com/content/v1/<myMerchantID>/items/products/schema/batch', {},"content"=> #feed, "Content-length"=>#feed.length.to_s, "GData-Version"=> "1", "Authorization" => "AuthSub token=myToken", "Content-Type"=> "application/atom+xml")

Are you Authenticating prior to your post?
https://developers.google.com/shopping-content/getting-started/authentication

Related

WebHarvest - Scrape data using authentication

I am using the WebHarvest tool to scrape web data from a few websites. I have gone through the examples, but was not able to find a way to authenticate in websites and then scrape data from them.
Can anyone please cite an example configuration to achieve web data scraping through authentication? How do I send the login parameters and then receive the home page content? Appreciate your help on this.
I just modified one example (http://web-harvest.sourceforge.net/samples.php?num=4) of Web Harvest and it is running fine with login credentials. You may get updated code and try:
<?xml version="1.0" encoding="UTF-8"?>
<config charset="ISO-8859-1">
<!-- sends post request with needed login information -->
<http method="post" url="http://www.nytimes.com/auth/login">
<http-param name="is_continue">true</http-param>
<http-param name="URI">http://</http-param>
<http-param name="OQ"></http-param>
<http-param name="OP"></http-param>
<http-param name="USERID">web-harvest</http-param>
<http-param name="PASSWORD">web-harvest</http-param>
</http>
<var-def name="startUrl">http://www.nytimes.com/pages/todayspaper/index.html</var-def>
<file action="write" path="D:/nytimes/nytimes${sys.date()}.xml" charset="UTF-8">
<template>
<![CDATA[ <newyourk_times date="${sys.datetime("dd.MM.yyyy")}"> ]]>
</template>
<loop item="articleUrl" index="i">
<!-- collects URLs of all articles from the front page -->
<list>
<xpath expression="//div[#class='story']">
<html-to-xml>
<http url="${startUrl}"/>
</html-to-xml>
</xpath>
</list>
<!-- downloads each article and extract data from it -->
<body>
<xquery>
<xq-param name="doc">
<var name="articleUrl"/>
</xq-param>
<xq-expression><![CDATA[
declare variable $doc as node() external;
$doc
]]></xq-expression>
</xquery>
</body>
</loop>
<![CDATA[ </newyourk_times> ]]>
</file>
</config>

Batch Delete Videos From YouTube Favorites Playlist

I am trying to batch delete videos from the user his YouTube favorites using the YouTube v2 API. (See also https://developers.google.com/youtube/2.0/developers_guide_protocol_batch_processing)
Posting videos to the favorites in batch works nicely; and I can also remove single videos from the favorites without problem (This rules out a problem with authentication).
My request body is as follows, where VIDEOID1 and VIDEOID2 are the <yt:favoriteId>Ids found in their corresponding video xml:
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:batch='http://schemas.google.com/gdata/batch' xmlns:yt='http://gdata.youtube.com/schemas/2007'>
<batch:operation type="delete"/>
<entry><id>VIDEOID1</id></entry>
<entry><id>VIDEOID2</id></entry>
</feed>
This is the response I get back however, where UserID ofcourse is the userID of the user and BatchID is the BatchID given by the service:
<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns='http://www.w3.org/2005/Atom'>
<id>https://gdata.youtube.com/feeds/api/users/USERID/favorites/batch/BATCHID</id>
<updated>2014-01-31T14:50:54.948Z</updated>
<category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#favorite'/>
<title>Batch Feed</title>
<entry xmlns:batch='http://schemas.google.com/gdata/batch'>
<id>VIDEOID1</id>
<updated>2014-01-31T14:50:54.948Z</updated>
<title>Error</title>
<content>Invalid entry Id/Uri</content>
<batch:status code='400' reason='Invalid entry Id/Uri'/>
</entry>
<entry xmlns:batch='http://schemas.google.com/gdata/batch'>
<id>VIDEOID2</id>
<updated>2014-01-31T14:50:54.949Z</updated>
<title>Error</title>
<content>Invalid entry Id/Uri</content>
<batch:status code='400' reason='Invalid entry Id/Uri'/>
</entry>
</feed>
It states Invalid entry Id/Uri for the videos I try to remove, while when I remove them by singular delete request with the same ID, it works.
Is batch deleting videos from favorites not supported, or am I missing something?
I've got it to work, thanks to this question and answer: Batch deleting videos using YouTube API and HTTpWebRequest
The trick was using the user its userId instead of default, and to use to complete video URL as id.
The batch URL looks like this:
https://gdata.youtube.com/feeds/api/users/USERID/favorites/batch?v=2&alt=json
The request looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:batch='http://schemas.google.com/gdata/batch' xmlns:yt='http://gdata.youtube.com/schemas/2007'>
<batch:operation type="delete"/>
<entry>
<id>https://gdata.youtube.com/feeds/api/users/USERID/favorites/VIDEOID1?v=2</id>
</entry>
<entry>
<id>https://gdata.youtube.com/feeds/api/users/USERID/favorites/VIDEOID2?v=2</id>
</entry>
</feed>

cannot get RTMP URL and stream key

I am developing code using the youtube API for live streaming. What I have done
I have registered a project in google and gotten client_id, client_secret, and
developer ID
I have done OAuth 2.0 and gotten the code and exchanged it to AUTH_TOKEN
I can create a live event by posting to domain gdata.youtube.com
with request
/feeds/api/users/default/live/events
with header
Authorization: Bearer AUTH_TOKEN
GData-Version: 2
Content-Type: application/atom+xml
X-GData-Key: key=DEV_ID
with content
<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns='http://www.w3.org/2005/Atom'
xmlns:media='http://search.yahoo.com/mrss/'
xmlns:yt='http://gdata.youtube.com/schemas/2007'>
<title>Test</title>
<summary>Test gogogogo!</summary>
<content type='application/atom+xml'>
<entry>
<yt:private/>
<yt:cdn name='primary'>
<media:content yt:format='18'/>
<media:content yt:format='19'/>
</yt:cdn>
</entry>
</content>
<yt:when start='2013-07-05T22:00:00.000Z'/>
</entry>
This returns HTTP code : 201 and my live event is created, but the returned data
does not include STREAM KEY AND RTMP URL. I need these data to start my live
event automatically.
the return data
<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns='http://www.w3.org/2005/Atom'
xmlns:app='http://www.w3.org/2007/app'
xmlns:media='http://search.yahoo.com/mrss/'
xmlns:gd='http://schemas.google.com/g/2005'
xmlns:yt='http://gdata.youtube.com/schemas/2007'
gd:etag='W/"CkEHR347eCp7I2A9WhFQEE0."'>
<id>tag:youtube.com,2008:live:event:XXXXXXXXXXXXXXXXXXXX</id>
<published>2013-07-05T05:03:56.000Z</published>
<updated>2013-07-05T05:03:56.000Z</updated>
<app:edited>2013-07-05T05:03:56.000Z</app:edited>
<category scheme='http://schemas.google.com/g/2005#kind'
term='http://gdata.youtube.com/schemas/2007#liveEvent'/>
<title>Test</title>
<summary>Test gogogogo!</summary>
<content type='application/atom+xml'
src='http://gdata.youtube.com/feeds/api/users/XXXXXXX/live/videos/XXXXXXXXX'/>
<link rel='self' type='application/atom+xml'
href='http://gdata.youtube.com/feeds/api/users/XXXXXXXXXXXXXXX/live/events/XXXXXXXXXXXXXXXXXX'/>
<link rel='edit' type='application/atom+xml'
href='http://gdata.youtube.com/feeds/api/users/XXXXXX/live/events/XXXXXXXXXXXXXXXXXXXXXX'/>
<author>
<name>XXXXXX</name>
<uri>http://gdata.youtube.com/feeds/api/users/XXXXXXXXXX</uri>
<yt:userId>XXXXXXXXXXXXX</yt:userId>
</author>
<media:group>
<media:description type='plain'>Test gogogogo!</media:description>
<media:title type='plain'>Test</media:title>
</media:group>
<yt:status>pending</yt:status>
<yt:when start='2013-07-05T22:00:00.000Z'/>
</entry>
If I manually login youtube and click on my create live event, I can see my
stream key and RTMP URL there. And I can use they to start streaming manually
So my problem is: how can I get STREAM KEY and RTMP URL automatically (by API
request)?
----EDIT----
based on https://developers.google.com/youtube/2.0/developers_guide_protocol_managing_live_events
it said that when I success create/adding an event, youtube will returns url like this
<yt:cdn name='primary'>
<media:content yt:format='19' yt:name='yt-live_SpQXZYILnN0_35'
url='rtmp://rtmp1.youtube.com/videolive?...'/>
</yt:cdn>
but in my case, my returned data doesn't include this line
After do some research, I solved it by sending this request
/feeds/api/users/default/live/events?inline=true
and the youtube returns me RTMP server URL
Thanks all

Import custom Atom feed in PowerPivot

Question: I have created a sample xml document containing data conforming to the atom 1.0 schema. When I import the contents of this file (for testing purposes) in PowerPivot, it creates columns for each atom element in each entry, instead of creating a column per content element. Why is this?
Background: A customer wants to import data from a web service which provides a feed that uses a custom XML schema that is not supported by PowerPivot. The service provides the ability for the caller to supply an XSLT template that will be applied to the feed. I am hoping to be able to transform this feed into a valid atom feed thereby allowing the customer to import data into PowerPivot.
Sample atom xml:
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns="http://www.w3.org/2005/Atom"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<title type="text">My Data Feed</title>
<id>http://temp/feed</id>
<updated>2012-12-13T00:00:00Z</updated>
<entry>
<id>http://temp/feed/1</id>
<title type="text">Title</title>
<author>
<name>Author</name>
</author>
<updated>2012-12-13T00:00:00Z</updated>
<content type="application/xml">
<d:Name>John Smith</d:Name>
<d:Address>Address</d:Address>
<d:Zip>1234</d:Zip>
</content>
</entry>
</feed>
When imported into PowerPivot (selecting "From Data Feeds", clicking "Browse" and pointing out the xml file), it looks like this:
I was excpecting three columns: Name, Address and Zip. If I change "Include Atom Elements" from Auto to False in the connection configuration, no columns are imported.
It seems I was just missing the m:properties element. Final result - also includes examples of null attributes and data types:
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns="http://www.w3.org/2005/Atom"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<title type="text">My Data Feed</title>
<id>http://temp/feed</id>
<updated>2012-12-13T00:00:00Z</updated>
<entry>
<id>http://temp/feed/1</id>
<title type="text">Title</title>
<author>
<name>Author</name>
</author>
<updated>2012-12-13T00:00:00Z</updated>
<content type="application/xml">
<!-- attributes placed under the properties element -->
<m:properties>
<d:Name>John Smith</d:Name>
<d:Address>Address</d:Address>
<d:Zip m:type="Edm.Int32">1234</d:Zip>
<d:Comment m:null="true" />
</m:properties>
</content>
</entry>
</feed>

resumable-create-media link

I'm creating an iOS app that will upload a file to a specific collection in Google Docs. How can I get the resumable-create-media link for that collection?
When I do a get request on the collection as recommended here: https://groups.google.com/forum/?fromgroups#!topic/google-documents-list-api/LOxHfIxVAec
I get the following xml (sadly no resumable-create-media)
<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns='http://www.w3.org/2005/Atom'
xmlns:docs='http://schemas.google.com/docs/2007'
xmlns:batch='http://schemas.google.com/gdata/batch'
xmlns:gd='http://schemas.google.com/g/2005'>
<id>https://docs.google.com/feeds/documents/private/full/folder%3A0B4Xm3k31FF25MXZzbjZvNzhZU00</id>
<published>2012-07-03T14:38:35.068Z</published>
<updated>2012-07-03T14:38:35.068Z</updated>
<category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/docs/2007#folder' label='folder'/>
<title type='text'>My Collection</title>
<content type='application/atom+xml' src='https://docs.google.com/feeds/folders/private/full/folder%3A0B4Xm3k31FF25MXZzbjZvNzhZU00'/>
<link rel='alternate' type='text/html' href='https://docs.google.com/#folders/folder.0.0B4Xm3k31FF25MXZzbjZvNzhZU00'/>
<link rel='http://schemas.google.com/docs/2007#icon' type='image/png' href='https://ssl.gstatic.com/docs/doclist/images/icon_9_collection_list.png'/>
<link rel='self' type='application/atom+xml' href='https://docs.google.com/feeds/documents/private/full/folder%3A0B4Xm3k31FF25MXZzbjZvNzhZU00'/>
<link rel='edit' type='application/atom+xml' href='https://docs.google.com/feeds/documents/private/full/folder%3A0B4Xm3k31FF25MXZzbjZvNzhZU00/h47320jg'/>
<author><name>xxxx</name>
<email>xxxx#gmail.com</email></author>
<gd:resourceId>folder:0B4Xm3k31FF25MXZzbjZvNzhZU00</gd:resourceId>
<gd:lastModifiedBy><name>stayaway</name><email>xxxx#gmail.com</email></gd:lastModifiedBy>
<gd:quotaBytesUsed>0</gd:quotaBytesUsed>
<docs:writersCanInvite value='true'/>
<gd:feedLink rel='http://schemas.google.com/acl/2007#accessControlList' href='https://docs.google.com/feeds/acl/private/full/folder%3A0B4Xm3k31FF25MXZzbjZvNzhZU00'/>
</entry>
Many Thanks
The Google Drive API has replaced the Documents List API.
A sample Objective-C application that demonstrates use of the Drive API, including uploading and downloading files, is here.

Resources