twitter image thumbnail in tweet - twitter

How to show images in twitter like instagram does ? what are the metatags twitter tries to find in the page to show as image thumbnail ? like when a twitpic or instagram link is provided .
like this example

I use http://embed.ly/
You can use the service to create a regex of all the image services, find those links, pass them to Embed.ly and get an image thumbnail back.
You can write a simple set of regular expressions for the most common service, here's one which I use.
'#youtube\.com\/watch\?v=([_-\d\w]+)#i' => 'http://i.ytimg.com/vi/%s/1.jpg',
'#youtu\.be\/([_-\d\w]+)#i' => 'http://i.ytimg.com/vi/%s/1.jpg',
'#qik\.ly\/([_-\d\w]+)#i' => 'http://qik.ly/%s.jpg',
'#twitpic\.com\/([\d\w]+)#i' => 'http://twitpic.com/show/thumb/%s',
'#twitgoo\.com\/([\d\w]+)#i' => 'http://twitgoo.com/show/thumb/%s',
'#hellotxt\.com\/i\/([\d\w]+)#i' => 'http://hellotxt.com/image/%s.s.jpg',
'#ts1\.in\/(\d+)#i' => 'http://ts1.in/mini/%s',
'#moby\.to\/\?([\w\d]+)#i' => 'http://moby.to/%s:square',
'#mobypicture\.com\/\?([\w\d]+)#i' => 'http://mobypicture.com/?%s:square',
'#twic\.li\/photo\/([\w]+)#i' => 'http://twic.li/userimg/thumb_%s.jpg',
'#tweetphoto\.com\/(\d+)#' => 'http://api.plixi.com/api/tpapi.svc/imagefromurl?url=http://tweetp$
'#plixi\.com\/p\/(\d+)#' => 'http://api.plixi.com/api/tpapi.svc/imagefromurl?url=http://plixi.$
'#phz\.in\/([\d\w]+)#' => 'http://api.phreadz.com/thumb/%s?t=code',
'#imgur\.com\/([\w]{5})[\s\.ls][\.\w]*#i' => 'http://imgur.com/%ss.png',
'#imgur\.com\/gallery\/([\w]+)#i' => 'http://imgur.com/%ss.png',
'#brizzly\.com\/pic\/([\w]+)#i' => 'http://pics.brizzly.com/thumb_sm_%s.jpg',
'#img\.ly\/([\w\d]+)#i' => 'http://img.ly/show/thumb/%s',
'#picplz\.com\/([\d\w\.]+)#' => 'http://picplz.com/%s/thumb',
'#pk\.gd\/([\d\w]+)#i' => 'http://img.pikchur.com/pic_%s_s.jpg',
'#pikchur\.com\/([\d\w]+)#i' => 'http://img.pikchur.com/pic_%s_s.jpg',
'#znl\.me\/([\d\w]+)#' => 'http://www.zannel.com/webservices/content/%s/Image-164x123-JPG.jp$
'#yfrog\.com\/([\d\w]+)#' => 'http://yfrog.com/%s:small',
'#instagr\.am\/p\/([_-\d\w]+)#i' => 'http://instagr.am/p/%s/media/?size=t',
'#instagram\.com\/p\/([_-\d\w]+)#i' => 'http://instagr.am/p/%s/media/?size=t',
'#twitrpix.com/([\d\w]+)#i' => 'http://img.twitrpix.com/thumb/%s',

You can use twitter cards for this
<meta name="twitter:card" content="photo" />
<meta name="twitter:site" content="#flickr" />
<meta name="twitter:title" content="Mountain sunset" />
<meta name="twitter:image" content="http://farm8.staticflickr.com/7334/11858349453_e3f18e5881_z.jpg" />
<meta name="twitter:url" content="https://www.flickr.com/photos/reza-sina/11858349453/" />
You can test your card on twitter card validator
If you find any robote.text issue you can do as in twitter documentation

Related

Facebook og:tags not working in my rails application

I am trying to add og:tags for sharing my URL on facebook. below is my code
in my view file,
- content_for :og_meta_tags do
%meta{:content => "#{FbAppId}", :property => "fb:app_id"}/
%meta{:content => "Travelibro blog", :property => "og:name"}
%meta{:content => #journey.photos.first.image.url, :property => "og:image"}
%meta{:content => "website", :property => "og:type"}/
%meta{:content => user_journey_url, :property => "og:url"}/
%meta{:content => "Travelibro - #{#journey.name}", :property => "og:title"}/
%meta{:content => "The TraveLibro app allows your to capture your live journeys On-The-Go with simple check-ins, picture uploads and thoughts to create a beautiful timeline of your travels. It enables friends travelling together to share experiences and post moments to a shared timeline and loved ones to see them in real time.", :property => "og:description"}
and my application.html.haml file contains the below code,
<!doctype html>
%html
%head{:prefix => "og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# website: http://ogp.me/ns/website#"}
%link{:href => "http://test.com", :rel => "canonical"}
= yield :og_meta_tags
.
.
.
but, when I scrape a new information from facebook debugger tool, I get the following errors,
a required property 'og:title' of type 'string' was not provided.
It's not picking up my og:tags at all.
For example, below is the URL to be share on the facebook :
http://travelibro.com/monish-shah/journeys/bangalore-day-trip-2149
when I put this URL to facebook debugger tool, I get the following error
Object at URL 'http://travelibro.com/monish-shah/journeys/bangalore-day-trip-2149' of type 'website' is invalid because a required property 'og:title' of type 'string' was not provided.

Rails tag helper

I want to do
<meta http-equiv="refresh" content="0;URL='my_url" />
with rails tag helper
i'm doing like this
tag(:meta, 'http-equiv' => (:refresh),:content=>("0;URL=#{my_url}"))
but i getting
"<meta content=\"0;URL=my_url" http-equiv=\"refresh\" />"
where is my mistake?

How to use LinkedIn's Share API with the Rails Gem

I'm running Rails 3, with the LinkedIn API gem: here
I've been unable to get the Share API working as described here
This works fine:
response = client.add_share(:comment => 'new share API')
This Fails with:
response = client.add_share(:comment => 'new share API', :title => 'Linkedin Share API', :url => 'http://developer.linkedin.com/docs/DOC-1212', :image_url => 'http://images.bizjournals.com/travel/cityscapes/thumbs/sm_sanfrancisco.jpg')
Error:
LinkedIn::Errors::GeneralError ((400): Invalid xml {Expected elements 'post-network-update#http://api.linkedin.com/v1 id#http://api.linkedin.com/v1 visibility#http://api.linkedin.com/v1 comment#http://api.linkedin.com/v1 attribution#http://api.linkedin.com/v1 content#http://api.linkedin.com/v1 private-message#http://api.linkedin.com/v1 share-target-reach#http://api.linkedin.com/v1' instead of 'image-url#http://api.linkedin.com/v1' here in element share#http://api.linkedin.com/v1, Expected elements 'post-network-update#http://api.linkedin.com/v1 id#http://api.linkedin.com/v1 attribution#http://api.linkedin.com/v1 content#http://api.linkedin.com/v1 private-message#http://api.linkedin.com/v1 share-target-reach#http://api.linkedin.com/v1' instead of 'url#http://api.linkedin.com/v1' here in element share#http://api.linkedin.com/v1}):
Any ideas? Thanks
You're doing it wrong. This is the XML in of sample request in https://developer.linkedin.com/documents/share-api#toggleview:id=xml
<share>
<comment>Check out the LinkedIn Share API!</comment>
<content>
<title>LinkedIn Developers Documentation On Using the Share API</title>
<description>Leverage the Share API to maximize engagement on user-generated content on LinkedIn</description>
<submitted-url>https://developer.linkedin.com/documents/share-api</submitted-url>
<submitted-image-url>http://m3.licdn.com/media/p/3/000/124/1a6/089a29a.png</submitted-image-url>
</content>
<visibility>
<code>anyone</code>
</visibility>
</share>
So the request should look something like this based in the sample request:
response = client.add_share(:comment => 'Sample Job',
:content => { :title => 'LinkedIn Developers Documentation On Using the Share API', :description => 'Leverage the Share API to maximize engagement on user-generated content on LinkedIn', :'submitted-url' => 'https://developer.linkedin.com/documents/share-api', :'submitted-image-url' => 'http://m3.licdn.com/media/p/3/000/124/1a6/089a29a.png' } )

Rails 3 ActionMailer - Gmail Classifies Message As Spam

My ActionMailer is set up to send an email once a user fills out an application. After upgrading to Rails 3 and ActionMailer, gmail now seems to be classifying the response email as spam.
I use google apps for the domain (hosted by dreamhost) and have it set up to send as smtp; and I am able to directly send emails to the same users from the google apps web account, and not have it classified as spam.
My question is: are there settings or values that I should have set in the ActionMailer (etc) that might circumvent this?
One recommendation I got was to set up and SPF, but I wasn't sure about this as I was using smtp via gmail.
Here is my configuration:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:user_name => "email#domain.org",
:password => "password",
:authentication => "plain",
:enable_starttls_auto => true
}
The email is rendered as html (have a plain text one too), with attachments of the files the user uploaded to the application.
<!DOCTYPE html>
<HTML>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
</head>
<body>
<p>
Dear <%= #f.first_name + " " + #f.last_name %>,<br>
<br>
etc....
Here is how my mailer is formatted
class EmploymentMailer < ActionMailer::Base
default :from => "email#domain.org"
def employment_app_email(f, files)
#f = f
#files = files
mail(:to => ['email#domain.org', f.email], :subject => "Subject")
files.each do |file|
attachments[file[1].original_filename] = File.open(file[1].path, 'rb'){|a| a.read}
end
end
end

Multiple files upload with Rails 3 and paperclip on heroku

I need an interface on my Rails 3 app to upload multiple files to Amazon S3 (because i'm on heroku), possibly with progress bars.
I've easily managed how to set up paperclip and upload single files, but i'm really lost now on how to go ahead.
Please can you give me some advices? It's 2 days i'm searching across all the internet, but i can't find a working solution
** EDIT **
I really can't understand... I'm going mad 'cause I'm losing too many hours on this... please help me.
If I try to open the example app cited by Johnny I only get this (and in my app it is the same):
Where is the UI?
Is there something wrong on my browser?
** EDIT 2 **
Here on GitHub you can find my testapp... please can you explain me why the damn upload UI is not showing up? Thanks!
** EDIT 3 **
Thank you very much Johnny, i wasn't aware of the fact that jquery and prototype can't live together.
Now the plugin is showing up correctly, but as a try to upload something it creates a new "upload" record, but its attachment field is blank, and the files are not on s3.
This is what the console is saying:
Started POST "/uploads" for 127.0.0.1 at 2011-06-27 16:17:22 +0200
Processing by UploadsController#create as JSON
Parameters: {"utf8"=>"✓", "authenticity_token"=>"GesRBTiZR1f2LV/bAeAdxWqF++gxcDJw4pPGStYGsH8=", "upload"=>{"attachment"=>[#<ActionDispatch::Http::UploadedFile:0x000001032834b8 #original_filename="animal-tiger-66550.jpg", #content_type="image/jpeg", #headers="Content-Disposition: form-data; name=\"upload[attachment][]\"; filename=\"animal-tiger-66550.jpg\"\r\nContent-Type: image/jpeg\r\n", #tempfile=#<File:/var/folders/Qj/QjEqvUUNGTmuki5SXOaaG++++TI/-Tmp-/RackMultipart20110627-1818-1syiex9>>]}}
AREL (0.5ms) INSERT INTO "uploads" ("attachment", "created_at", "updated_at", "attachment_file_name", "attachment_content_type", "attachment_file_size", "attachment_updated_at") VALUES (NULL, '2011-06-27 14:17:23.049136', '2011-06-27 14:17:23.049136', NULL, NULL, NULL, NULL)
[paperclip] Saving attachments.
Completed 200 OK in 64ms (Views: 4.2ms | ActiveRecord: 0.7ms)
You can look at jQuery-File-Upload. Demo here and rails 3/Paperclip setup here.
Edit: As #apneadiving mentioned, the library has been updated to version 5. The script you have is for verison 4. You should try modifying this to work with PaperClip. Copy-pasting the majority of the example code into my app (with a few modifications) worked for me:
#app/public/javascripts/application.js
$(function () {
// Initialize the jQuery File Upload widget:
$('#fileupload').fileupload();
// Load existing files:
$.getJSON($('#fileupload form').prop('action'), function (files) {
var fu = $('#fileupload').data('fileupload');
fu._adjustMaxNumberOfFiles(-files.length);
fu._renderDownload(files)
.appendTo($('#fileupload .files'))
.fadeIn(function () {
// Fix for IE7 and lower:
$(this).show();
});
});
// Open download dialogs via iframes,
// to prevent aborting current uploads:
$('#fileupload .files a:not([target^=_blank])').live('click', function (e) {
e.preventDefault();
$('<iframe style="display:none;"></iframe>')
.prop('src', this.href)
.appendTo('body');
});
});
#app/controllers/uploads_controller.rb
def create
#upload = Upload.new(params[:upload])
if #upload.save
render :json => [{
:pic_path => #upload.attachment.url.to_s ,
:name => #upload.attachment.instance.attributes["picture_file_name"]
}], :content_type => 'text/html'
else
render [:json => { :result => 'error'}], :content_type => 'text/html'
end
end
#app/views/uploads/new.html.haml
%link#theme{:href => "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/themes/base/jquery-ui.css", :rel => "stylesheet"}
= stylesheet_link_tag 'jquery.fileupload-ui'
#fileupload
= form_for Upload.new, :html => { :multipart => true } do |f|
.fileupload-buttonbar
%label.fileinput-button
%span Add files...
= f.file_field :attachment, :multiple => true
%button.start{:type => "submit"} Start upload
%button.cancel{:type => "reset"} Cancel upload
%button.delete{:type => "button"} Delete files
.fileupload-content
%table.files
.fileupload-progressbar
%script#template-upload{:type => "text/x-jquery-tmpl"}
%tr{:class => "template-upload{{if error}} ui-state-error{{/if}}"}
%td.preview
%td.name ${name}
%td.size ${sizef}
{{if error}}
%td.error{:colspan => "2"}
Error:
{{if error === 'custom_failure'}}Custom Error Message
{{else}}${error}
{{/if}}
{{else}}
%td.progress
%div
%td.start
%button Start
{{/if}}
%td.cancel
%button Cancel
%script#template-download{:type => "text/x-jquery-tmpl"}
%tr{:class => "template-download{{if error}} ui-state-error{{/if}}"}
{{if error}}
%td
%td.name ${name}
%td.size ${sizef}
%td.error{:colspan => "2"}
Error:
{{if error === 1}}File exceeds upload_max_filesize (php.ini directive)
{{else}}${error}
{{/if}}
{{else}}
%td.preview
{{if thumbnail_url}}
%a{:href => "${url}", :target => "_blank"}
%img{:src => "${thumbnail_url}"}/
{{/if}}
%td.name
<a href="${url}"{{if thumbnail_url}} target="_blank"{{/if}}>${name}
%td.size ${sizef}
%td{:colspan => "2"}
{{/if}}
%td.delete
%button{"data-type" => "${delete_type}", "data-url" => "${delete_url}"} Delete
Edit
Had a quick look at your app, the problem is that you are mixing prototype with jquery. The easiest way around this is to switch to jQuery using jquery-rails.
#Gemfile
gem 'jquery-rails'
Next, run bundle install and then rails g jquery:install.
Then change your app/views/layouts/application.erb to this:
<%= stylesheet_link_tag :all %>
<%= csrf_meta_tag %>
<%= javascript_include_tag 'jquery.min' %>
<%= javascript_include_tag 'jquery-ui-1.8.13.custom.min' %>
<%= javascript_include_tag 'jquery.tmpl.min' %>
<%= javascript_include_tag 'jquery.iframe-transport' %>
<%= javascript_include_tag 'jquery.fileupload' %>
<%= javascript_include_tag 'jquery.fileupload-ui' %>
<%= javascript_include_tag 'jquery_ujs' %>
<%= javascript_include_tag 'application' %>
Note that I removed the
<%= javascript_include_tag :defaults %>
So that I can specify the order in which jquery, jquery_ujs, and application are loaded.
I've begun with a very similar task recently, and the swf plugin (at least the more recent one) will indeed let you update paperclip's record. It has callbacks for just about everything you'd need to extend.
:onUploadComplete (upload_options,event)
Here's Nathan Colgate's gist on the matter. He just makes a remote call to the rails server once the upload is finished telling it of the locations for the paperclip attachment.
from his uploadCompleteHandler
var uploadCompleteHandler = function(upload_options,event){
$.ajax({
url: '<%= notify_rails_of_successful_upload_path(:format => :js)%>',
global: false,
type: 'POST',
data: ({
'authenticity_token' : '<%= form_authenticity_token %>',
'upload' : {
'file_file_name' : upload_options.FileName,
'file_file_size' : upload_options.FileSize,
'file_content_type' : upload_options.ContentType
}
}),
dataType: 'script'
}
)
};
I'm not sure if this exact callback gets triggered for each file; it definitely looks like it would. But he passes everything paperclip needs back through an ajax request. filename,size,content-type. This way all that gets sent to heroku is some text about the file, sparing your app a good amount of work by giving it to the client.
edit: flash is the only way I've found to avoid sending a lot of data through heroku to s3. There are a few html5/js-only uploaders that might be able to get the job done, but the ones I have found are still pretty ripe on the dev tree.
As per Heroku support, see this.
Paperclip & multiple files upload, although not S3 specific.
View: (notice the array blog_post[avatars][])
<form accept-charset="UTF-8" action="/blog_posts" enctype="multipart/form-data" id="new_blog_post" method="post">
<div style="margin:0;padding:0;display:inline">
<input name="utf8" type="hidden" value="✓" />
<input name="authenticity_token" type="hidden" value="<%=form_authenticity_token %>" />
</div>
<p><input id="blog_post" name="blog_post[avatars][]" type="file" multiple /></p>
<p><input name="commit" type="submit" value="Upload" /></p>
</form>
Controller:
# POST /blog_posts
# POST /blog_posts.json
def create
#blog_post = BlogPost.new(params[:blog_post])
#blog_post.avatars.each do |avatar|
each_blog_post = BlogPost.new
each_blog_post.avatar = avatar
if each_blog_post.save
end
end
end
Model:
class BlogPost < ActiveRecord::Base
attr_accessible :title, :avatar, :avatars
has_attached_file :avatar
attr_accessor :avatars
end

Resources