Don't show 's3.amazon.com' when posting images to LinkedIn API - linkedin-api

I am posting images to LinkedIn through the public api with my app that pulls the images from our S3 bucket. When the update appears on LinkedIn it shows 's3.amazon.com' next to the image. Is there any way that I can keep this from happening?
Ruby Code from app:
def post(message_body, attachment, post)
options = { :visibility => { :code => 'anyone' } }
if attachment.present?
options.merge!(:content => { :title => 'titles',
:description => 'descriptions',
:submitted_url => 'http://s3.amazonaws.com/...'
}, :comment => message_body)
else
options.merge!(:comment => message_body)
end
response = client.add_share(options)
post.posted!
JSON.parse(response.body)['updateUrl']
rescue LinkedIn::Errors::UnauthorizedError => e
raise SocialProfile::UnauthorizedError, e.message
rescue LinkedIn::Errors::AccessDeniedError => e
raise SocialProfile::UnauthorizedError, e.message
## Heading ##end

Related

Being redirected to old PayPal UI incorrectly

i have integrated paypal to my ecommerce using ruby on rails but it always redirected to the old paypal UI instead of the latest UI. here is the old UI i mentioned:
here is roughly my code. once create order submit button pressed, my order controller will redirect to the encrypted paypal link.
order_controller.rb
def create
redirect_to #order.paypal_url(root_url, shipping_fees, payment_notification_url)
in my order model, the encrypted link code as below:
order.rb
def paypal_url(return_url, shipping_fees, notify_url)
encrypted = {
:cmd => "_s-xclick",
:encrypted => self.encrypt_for_paypal(return_url, shipping_fees, notify_url),
}
"https://www.paypal.com/cgi-bin/webscr?" + encrypted.to_query
end
def encrypt_for_paypal(return_url, shipping_fees, notify_url)
#def paypal_url(return_url, shipping_fees, notify_url)
values = {
:business => 'cxxx#hotmail.com',
:cmd => '_cart',
:upload => 1,
:currency_code => 'MYR',
:return => return_url,
:invoice => self.number,
:notify_url => notify_url,
:cert_id => "XXX",
}
line_items.each_with_index do |item, index|
values.merge!({
"amount_#{index+1}" => item.final_price,
"item_name_#{index+1}" => Product.where(id: item.variant.product_id).pluck(:title),
"item_number_#{index+1}" => item.variant.SKU,
"quantity_#{index+1}" => item.quantity,
"shipping_1" => shipping_fees
})
end
encrypted_paypal(values)
end
PAYPAL_CERT_PEM = File.read("#{Rails.root}/certs/paypal_cert.pem")
APP_CERT_PEM = File.read("#{Rails.root}/certs/app_cert.pem")
APP_KEY_PEM = File.read("#{Rails.root}/certs/app_key.pem")
def encrypted_paypal(values)
signed = OpenSSL::PKCS7::sign(OpenSSL::X509::Certificate.new(APP_CERT_PEM), OpenSSL::PKey::RSA.new(APP_KEY_PEM, ''), values.map { |k, v| "#{k}=#{v}" }.join("\n"), [], OpenSSL::PKCS7::BINARY)
OpenSSL::PKCS7::encrypt([OpenSSL::X509::Certificate.new(PAYPAL_CERT_PEM)], signed.to_der, OpenSSL::Cipher::Cipher::new("DES3"), OpenSSL::PKCS7::BINARY).to_s.gsub("\n", "")
end
please advise because i read somewhere i need to insert :method => POST to the link but im not sure how. many thanks

Facebook Marketing API - Ad Creative not generating properly

I'm working on a script to generate Facebook ads through the API. For some reason the variables for the ad creative are not being added to the ad. The main issue is the title and body are not being added. Here's the code I have for generating the ad creative:
try{
$creative = new AdCreative(null, $accountId);
$creative->setData(array(
AdCreativeFields::NAME => $ad_info['Ad Name'],
AdCreativeFields::TITLE => $ad_info['Title'],
AdCreativeFields::BODY => $ad_info['Body'],
AdCreativeFields::IMAGE_HASH => $image->hash,
//AdCreativeFields::OBJECT_URL => $ad_info['Preview Link'],
AdCreativeFields::OBJECT_STORY_SPEC => $object_story_spec,
AdCreativeFields::URL_TAGS => $ad_info['URL Tags'],
));
$creative->create();
echo 'Creative ID: '.$creative->id . "\n";
}
catch (Exception $e) {
echo '<pre>creative';print_r($e);exit;
if($e->getMessage()){
echo 'Error message: ' .$e->getMessage() ."\n" . "<br/>";
}
//echo 'Error Code: ' .$e->getCode() ."<br/>";
}
And the code for adding the creative to the ad:
$ad = new Ad(null, $accountId);
$ad->setData(array(
AdFields::CREATIVE =>
array('creative_id' => $creative->id),
AdFields::NAME => $ad_info['Ad Name'],
AdFields::ADSET_ID => $adsetId,
AdFields::STATUS => 'ACTIVE',
AdFields::TRACKING_SPECS => array('action.type' => $ad_info['action type'], 'fb_pixel' => $fb_pixel),
));
$ad->create();
It's not throwing errors, and the other variables, such as ad name, status, etc. all appear to be added to the ad correctly. As near as I can tell all of the above is correct according to Facebook's API documentation. I even tried throwing a sleep function in between the creative being generated and adding it to the ad. What could the issue be?
I figured out what the issue is. The ad creative object isn't applied to an ad if it's a link ad, which the ads this script is generating are. In order to get things like the the title and body text to appear, you have to add them in the AdCreativeLinkData like so:
$link_data->setData(array(
AdCreativeLinkDataFields::DESCRIPTION => $ad_info['Link Description'],
AdCreativeLinkDataFields::LINK => $ad_info['Link'],
AdCreativeLinkDataFields::NAME => $ad_info['Title'],
AdCreativeLinkDataFields::MESSAGE => $ad_info['Body'],
AdCreativeLinkDataFields::IMAGE_HASH => $image->hash,
AdCreativeLinkDataFields::CALL_TO_ACTION => array(
'type' => AdCreativeCallToActionTypeValues::SIGN_UP,
'value' => array(
'link' => $ad_info['Link'],
'link_caption' => $ad_info['Link'],
),
),
));
Once I added the NAME and MESSAGE variables to this object, the title and body of the ad showed up perfectly.

Promoted Object Is Missing when creating a Creative on Facebook Marketing API

I'm trying to create a new ad creative with the following HTTP request
response = HTTParty.post(
"https://graph.facebook.com/v2.9/act_#{account_id}/adcreatives",
:query => {
:ad_format => "DESKTOP_FEED_STANDARD",
:access_token => #ads_access_token,
:creative => {
:object_story_spec => {
:object_id => page_id,
:link_data => {
:call_to_action => {
:type => ad_cta,
:value => {
:link => ad_url
}
},
:link => ad_url,
:message => ad_text,
:description => ad_description,
:name => ad_headline,
:picture => ad_image_url
},
:page_id => "233558376717908"
}
}
}
)
But unfortunately I keep on getting the following error:
{"error"=>
{"message"=>"Invalid parameter",
"type"=>"OAuthException",
"code"=>100,
"error_subcode"=>1487930,
"is_transient"=>false,
"error_user_title"=>"Promoted Object Is Missing",
"error_user_msg"=>
"Your campaign must include an ad set with a selected object to promote related to your objective (ex: Page, URL, event). Please update your ad set to continue..",
"fbtrace_id"=>"DpnhEGhLaSj"}}
I did set up a promoted object for the adset, but I don't understand what it has to do with the adcreative.
Thanks!

Facebook GraphAPI App actions on wall post not working

I've been trying to post app specific actions to wall posts but nothing seems to help. What am I doing wrong?
oauth = Koala::Facebook::OAuth.new(CLIENT_ID, CLIENT_SECRET, "http://myurl.com/fb_auth")
token = oauth.get_access_token(params[:code])
graph = Koala::Facebook::API.new token
p graph.put_wall_post("explodingdog!", {
:link => "http://youtube.com/",
:caption => "Youtube",
:actions => [{:name => "Share", :link => "http://google.com"}]
})
You must convert actions to JSON string, using json gem this is how you will do it:
gem install json
then use to_json to convert your array to json:
oauth = Koala::Facebook::OAuth.new(CLIENT_ID, CLIENT_SECRET, "http://myurl.com/fb_auth")
token = oauth.get_access_token(params[:code])
graph = Koala::Facebook::API.new token
p graph.put_wall_post("explodingdog!", {
:link => "http://youtube.com/",
:caption => "Youtube",
:actions => [{:name => "Share", :link => "http://google.com"}].to_json
})
You are done :)

iphone can't post to my rails app

So I have been trying out several different ways to connect my iPhone app to my ROR restful backend and all seems to work ok pulling down data (json) with 'get' requests, but when posting I am unable to do so. I have tried ObjectiveResource and two or three others and they all have the same issue. I am thinking its something set wrong in my ROR app? I did notice all the example iPhone projects use https for production apps, does a production app need to https for an iPhone to establish a session and be able to post?
HERE is what I get for an error if I use http://localhost:3000/posts
Processing PostsController#create (for 127.0.0.1 at 2011-04-05 20:49:42) [POST]
Parameters: {"post"=>{"budget"=>"222"}}
User interests hash: false
NoMethodError (undefined method posts' for false:FalseClass):
app/controllers/posts_controller.rb:113:increate'
If I use http://localhost:3000
Processing PostsController#index (for 127.0.0.1 at 2011-04-05 20:49:42) [POST]
Parameters: {"post"=>{"budget"=>"222"}}
Here is my Create method:
def create
##post = Post.new(params[:post])
#post = current_user.posts.build(params[:post])
respond_to do |format|
if #post.save
flash[:notice] = 'Post was successfully created.'
format.html { redirect_to(#post) }
format.xml { render :xml => #post, :status => :created, :location => #post }
format.json { render :json => #post, :status => :created, :location => #post }
else
format.html { render :action => "new" }
format.xml { render :xml => #post.errors, :status => :unprocessable_entity }
format.json { render :json => #post.errors, :status => :unprocessable_entity }
end
end
end
Here is the method:
# POST /posts
# POST /posts.xml
def create
##post = Post.new(params[:post])
#post = current_user.posts.build(params[:post])
respond_to do |format|
if #post.save
flash[:notice] = 'Post was successfully created.'
format.html { redirect_to(#post) }
format.xml { render :xml => #post, :status => :created, :location => #post }
format.json { render :json => #post, :status => :created, :location => #post }
else
format.html { render :action => "new" }
format.xml { render :xml => #post.errors, :status => :unprocessable_entity }
format.json { render :json => #post.errors, :status => :unprocessable_entity }
end
end
end
Iphone call:
// CRUD methods using Resource.h
- (void)createRemote {
NSString *url =
[NSString stringWithFormat:#"%#/posts", siteURL];
[Resource post:[self params] to:url];
}
%#/posts is equal to http://localhost:3000/posts
Do you have protect_from_forgery set on your ApplicationController?
This essentially kills POSTing information from anywhere except the forms on your website. Try commenting it out and see if things start working.
As peterjb said, check for forgery protection. If you're on rails 3 then look for the csrf_meta_tag in your application.html.erb.
https -- is not must, it is how your server configures for the security needs. You can have http and https both no issues.
I suggest you to have look at the log in ROR app end too know what you get HTTP POST data -- if you are not able to get any data in ROR app end post some code which does POST request from your iPhone, people can analyse it better.