Giter Club home page Giter Club logo

angular-socialshare's Introduction

Angular Social Share

Angular Social Share is a collection of directives which lets you easily share your links various social networks. Currently Facebok, Google, Twitter and Linkdin are supported. Social Networks get the Meta data of the shared content like Title, Summary and Image from the Meta tags on the page by scraping. But Single Page Apps like Angular are unable to support crawling. But these dirictives use alternative so that Meta data is displayed where it is possible. Checkout the Demo. Change Log

As of Verstion 1 This directive supports two way binding of data, so now you can populate the data in the directive from a HTTP request.

Future Plans

Support asyncronous loading of corresponding social plugin javascript assets.

Getting Started

Install the library through bower.

bower install angular-socialshare

Include the script (and optional css file) in your html file.

<link rel='stylesheet' href="bower_components/angular-socialshare/angular-socialshare.min.css">
<script src="bower_components/angular-socialshare/angular-socialshare.min.js"></script>

Add to your APP's dependency.

angular.module('testing',['djds4rce.angular-socialshare'])

IMPORTANT

For Correct Sharing of links and updating share count you must enable HTML5 Mode True for your application. i.e No # in URL'S .

angular.module('testing').config(function($locationProvider){
    $locationProvider.html5Mode(true).hashPrefix('!');
});

HTML5 Mode requires server configration Explained Here

Share on Facebook

Facebook share uses facebook API which requires us to provide a APPID. Register a facebook app and Configure the APPID in your appplication. Note that you will get an error regarding 'not permitted URL' if you are testing this button in a localhost environment.

angular.module('testing').run(function($FB){
  $FB.init('YOUR_APPID', 'COUNTRY_CODE'); // Country code format example: fr_FR
});

Use the Facebook Directive

 <a facebook class="facebookShare" data-url='http://google.com' data-shares='shares'>{{ shares }}</a>

As we are using Facebook share API and not the facebook share button, you will have to style your own Facebook button, or use the provided stylesheet that has styles for the horizontal count button. You also need to display the share count, which the directive fetches from a diffrent API. The directive has transclusion set to true. The latest Facebook share API only allows for a URL to be supplied, it will scrape the other data (image, title, description) from the supplied URL.

The Attributes for the directives are

/*
data-url: URL of the Shared Content
data-shares: The Scope variable on which share count will be binded to. This lets you put
multiple share buttons on a single page and bind the share count to the respective model object.
data-callback: The Scope function which will receive [FB's Response object](https://developers.facebook.com/docs/javascript/reference/FB.ui)
data-translate: To change the text of the button. EX: data-translate="'Partager'"
*/

Share via Feed Dialog

The feed dialog works in the same way as the normal share dialog, but also has some addittional attributes available

 <a facebook-feed-share class="facebookShare" data-url='http://google.com' data-shares='shares', data-description="Example text">{{ shares }}</a>
/*
data-url: URL of the Shared Content
data-shares: The Scope variable on which share count will be binded to. This lets you put
multiple share buttons on a single page and bind the share count to the respective model object.
data-picture: The URL of a picture attached to the share. The picture must be at least 200px by 200px.
data-source: The URL of a media file (either SWF or MP3) attached to this share. If SWF, you must also specify picture to provide a thumbnail for the video.
data-name: The name of the link attachment.
data-caption: The caption of the link (appears beneath the link name). If not specified, this field is automatically populated with the URL of the link.
data-description: The description of the link (appears beneath the link caption). If not specified, this field is automatically populated by information scraped from the link, typically the title of the page.
data-properties: A JSON object of key/value pairs which will appear in the stream attachment beneath the description, with each property on its own line. Keys must be strings, and values can be either strings or JSON objects with the keys text and href.
data-actions: A JSON array containing a single object describing the action link which will appear next to the 'Comment' and 'Like' link under posts. The contained object must have the keys name and link.
data-callback: The Scope function which will receive [FB's Response object](https://developers.facebook.com/docs/javascript/reference/FB.ui)
data-translate: To change the text of the button. EX: data-translate="'Partager'"
*/

Twitter

Include the twitter javascript in your HTML.

<script src="http://platform.twitter.com/widgets.js"></script>

Add Directive to the element where you want to display your Twitter Button

<a twitter  data-lang="en" data-count='horizontal' data-url='http://google.com' data-via='notsosleepy' data-size="medium" data-text='Testing Twitter Share' ></a>

The Attributes for the directives are

/*
data-lang: Language of the tweet
data-url: URL of the Shared Content
data-count: Position of the share counter
data-size: Size of the tweet button
data-text: Content of the tweet
data-via: User handle which will be tagged in the tweet
For options checkout https://dev.twitter.com/docs/tweet-button
*/

Linkedin

Although Linkedin has a share button and also a Javascript share API it does not take the title and the content as its parameters hence we will have to use the raw share URL to share the content.

Use the Linkedin Directive

<div linkedin class="linkedinShare" data-url='http://www.google.com.au' data-title='Linkedin Share' data-summary="testing Linkedin Share" data-shares='linkedinshares'>{{linkedinshares}}</div>

Linkedin Directive works similar to the Facebook Mechanism. This will force us to add our own style to the button and also display count which is fetched by the directive through a diffrent API. The supplied stylesheet contains styling for the horizontal styled button.

The Attributes for the directives are

/*
data-title: Title of the Shared Content
data-url: URL of the Shared Content
data-summary: Summary of the content
data-shares: The Scope variable on which share count will be binded to. This lets you put
multiple share buttons on a single page and bind the share count to the respective model object.
data-translate: To change the text of the button. EX: data-translate="'Partager'"
*/

Google +

 <div gplus class="g-plus" data-size="tall" data-annotation="bubble" data-href='http://google.com' data-action='share'></div>

For more information on the share button attributes check the Google Share Documentation

If you change the class of the button to `g-plusone' it will be converted to a google plus one button.

Tumblr

Link Share

Include the tumblr javascript in your HTML.

<script src="http://platform.tumblr.com/v1/share.js"></script>
<div tumblr-text data-url='http://google.com' data-name='Sharing to Tumblr' data-title='test' data-buttontext='Sharing Text' data-styling="display:inline-block; text-indent:-9999px; overflow:hidden; width:129px; height:20px; background:url('http://platform.tumblr.com/v1/share_3.png') top left no-repeat transparent;" data-description='this is awesome'></div>

The Attributes for the directives are

/*
data-url: URL of the content to be shared
data-name: Name of the content URL
data-title(Optional): Title of the button on hover
data-description: Description of the URL
data-style(Optional): Style of the button
*/

Qoute Share

<div tumblr-qoute data-qoute='Texting Tumblr Qoute share' data-source='http://djds4rce.github.io'></div>

The Attributes for the directives are

/*
data-source: Source URL of the qoute to be shared
data-qoute: Qoute to be shared
data-title(Optional): Title of the button on hover
data-style(Optional): Style of the button
*/

Image Share

<div tumblr-image data-source='http://plnkr.co/img/plunker.png' data-caption='Image Share' data-clickthru='http://google.com'></div>

The Attributes for the directives are

/*
data-source: Source URL of the Image to be shared
data-caption: Caption for the image
data-clickthru: clickthru URL for the image
data-title(Optional): Title of the button on hover
data-style(Optional): Style of the button
*/

Image Share

<div tumblr-video data-embedcode='<iframe width="560" height="315" src="//www.youtube.com/embed/aqHBLS_6gF8" frameborder="0" allowfullscreen></iframe>'></div>

The Attributes for the directives are

/*
data-embedcode: Embed code for the external video
data-caption: Caption for the Video
data-title(Optional): Title of the button on hover
data-style(Optional): Style of the button
*/

Pinterest

Include the Pinterest javascript in your HTML.

<script type="text/javascript" src="//assets.pinterest.com/js/pinit.js" data-pin-build='parsePins'></script>

Usage

<div pintrest data-href='http://google.com' data-description='testing share' data-img='http://plnkr.co/img/plunker.png' data-pin-do='buttonPin' data-pin-config='beside'></div>

The Attributes for the directives are

/*
data-href: Url To be shared
data-Description: Description of the content
data-img: Image for the Pin
data-pin-do(Optional): Type of pin
data-pin-config(Optional): Pin count Orientation 'beside' or 'above'
*/

Made with Love by Djds4rce Additions with ♡ by haxxxton

Licenced Under MIT Licence.

angular-socialshare's People

Contributors

aubm avatar bryant1410 avatar burstaholic avatar charlesdg avatar djds4rce avatar gion avatar haxxxton avatar jsknight avatar khasinski avatar lycwed avatar maks-rafalko avatar mariusz avatar markbirbeck avatar mickeywu avatar rshetty avatar studiowebux avatar tahashahid avatar tplaindoux avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angular-socialshare's Issues

Syntax error on package.json

Heya,

On the version downloaded by bower there is still a syntax error on package.json (mismatched ")

"version": "1.4.2,

I noticed it is fixed in the source code, but since it's not on the release then bower downloads the wrong one. In my specific case, I'm loading this package via webpack, and it doesn't even allow me to load anything there since package.json is invalid.

(as a side-note, version should also be 1.4.3)

Cheers

Doesn't work on device

Hi,
I am developing a hybrid application, which needs social sharing. I tried with facebook sharing and it doesn't work. Nothing happens when I tap on share button. However, when I run on browser, I get this error:
'Given URL is not allowed by the Application configuration: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains.'

Any suggestions?

Pass in dynamic values

Hi,

I'm doing a $http.get call to the backend to retrieve content, and subsequently setting a product title on the page. I want to pass this product.title into

a(twitter='', data-lang='en', data-count='horizontal', data-url='', data-via='', data-size='medium', data-text='{{product.title}}')

It doesn't appear to work.

In addition, the facebook directive doesn't appear to get the url automatically from window.location.href, along when there is '0' shares, I get an error message:

TypeError: Cannot read property 'share_count' of undefined

Twitter doesn't appear in Mobile Chrome/iOS7

The Twitter share button doesn't appear when viewed on an iPhone w/ iOS7 in Mobile Chrome, though it does appear in Safari. I tried pulling up the Plunker demo and noticed the same there.

Twitter button not coming in firefox

Hey
First of all, thanks for such a great plugin. The plugin runs smoothly in chrome, but for some reasons the tweet button is not coming in firefox, the version I am using is 41.0.2. I can see the iframe in the page source, but their's visibility is set to hidden and height/width is set to 0.

The developers community of twitter says that it should work on firefox 36+.

Any ideas, why it isn't working..?

Thanks
Gautam Pahuja

toString() error

Hi, I have an error that I cant understand. Here is my log:

TypeError: Cannot read property 'toString' of undefined
at angular-socialshare.js:73
at angular.min.js:80
at angular.min.js:112
at l.$eval (angular.min.js:125)
at l.$digest (angular.min.js:122)
at l.$apply (angular.min.js:126)
at l (angular.min.js:81)
at S (angular.min.js:85)
at XMLHttpRequest.D.onload (angular.min.js:86)

I don't kwon how to resolve that, Is there a problem with angular-socialshare?

Thank you!

Twitter not show count data.

My code is below.

<a twitter data-lang="en" data-count='horizontal' data-url='{{shareUrl}}' data-size="medium" data-text='Tweet' ></a>

Tweet count data not show.

Outdated API used to get stats from Facebook.

I'm receiving the following error either when using facebook share or facebook feed share button in console and share counts are not getting updated.

XMLHttpRequest cannot load https://api.facebook.com/method/links.getStats?urls=http://www.onlinecmr.in…hina-cuts-corn-surplus-estimate-on-higher-demand-lower-imports&format=json. Request header field API_KEY is not allowed by Access-Control-Allow-Headers in preflight response.

I thought it might because of the changeset #72 . Digging further landed up in the SO question at: http://stackoverflow.com/questions/39028734/get-facebook-share-like-comment-count-of-url , http://stackoverflow.com/questions/37491742/getting-facebook-share-like-and-comment-counts-for-a-given-url-with-api-graph-v and noticed the following in directive:

$http.get('https://api.facebook.com/method/links.getStats?urls=' + attr.url + '&format=json', {withCredentials: false}).success(function(res) {
 // success callback goes here
})

Here, what and all we've to send using new FQL to get counts? How it can be fixed?

Integrate with Cordova / Phonegap

Hi! I've been trying to use the angular-socialshare on a Phonegap / Cordova (v. 6.0.0) app on iOS.

When clicking on the button

<a facebook role="button" class="btn btn-fb btn-lg center-block" data-url="https://URL_TO_REST_SERVICE/shareOnFB?token_auth={{getTokenAuth()}}&uid={{getTransactionId()}}&format=html">Share on Facebook</a>

Won't do anything. No errors on console.

Any suggestions?

Data completion from ng-repeat.

Hi.
I have a page with posts. It draws through ng-repeat.
Can i pass data into item with {{ }} or can i use controller function getSocialLink() that returns URL string ?

My code:

<div ng-repeat="post in loadedPosts">
    <h2>{{post.title}}</h2>
    <img ng-src={{post.preview_img}} alt="{{post.title}}"/>
    <div>
        <a facebook class="facebookShare"
           data-url='getSocialLink($index)'
           data-shares='shares'>{{ shares }}</a>
            ....
        <div linkedin class="linkedinShare"
             data-url='{{post.url}}'
             data-title='{{post.title}}'
             data-summary="{{post.description}}"
             data-shares='linkedinshares'>{{linkedinshares}}</div>
    </div>
    <p class="preview" ng-bind-html="post.preview"></p>
    <a href="{{links.getLink(currentRoute())}}/{{post.slug}}" class="read_more pull-left">{{"MORE_BUTTON"|translate}}</a>
</div>

tumblr share

I have the need to share with tumblr. do you have plan to integrate tumblr share functionality in the very near future ?

if i would like to add tumblr , could u please give me any advices or best practises ?

Installation problem

screen shot 2014-05-08 at 16 49 42
when try install give me this error message:

bower angular-bootstrap#1.2.11 ENORESTARGET No tag found that was able to satisfy 1.2.11

and stop the installation.

Possible malware code in this library?

I'm busting my head how is it possible that an advertisement link gets injected into the share and I'm just concerned that malicious code has been packaged in to the .min script of this library. Better safe than sorry.

screen shot 2016-11-21 at 17 25 05

Duplicated tweet button

Hi!

First of all, congratulations for this project! Its awesome.

In my Angular JS project, I'm using the tweet button and sometimes It appears duplicated. This is my code (I'm using Jade template engine)

a(twitter 
          data-lang='es' 
          data-count='horizontal' 
          data-url='http://referi.co'
          data-via='ReferiApp'
          data-size='medium'
          data-text='EN VIVO: {{match.team1.name}} {{match.team1_score}}-{{match.team2_score}} {{match.team2.name}}')

bug

This is great however I think it is outdated...

I'm getting this when the call to api.facebook is made:

{"error_code":12,"error_msg":"REST API is deprecated for versions v2.1 and higher (12)","request_args":[{"key":"method","value":"links.getStats"},{"key":"urls","value":"www.mpi-mps.org"},{"key":"format","value":"json"}]}

?????

Dynamic value for twitter and facebook

Hi guys, I would pass dynamic value to url for facebook e twitter share.
I've this code

<a facebook class="facebookShare" data-url='http://mysite.com/videos/{{video.id}}' data-shares='shares'>{{ shares }}</a>
<a twitter  data-lang="en" data-count='horizontal' ng-data-url='http:///mysite.com//videos/{{video.id}}' data-via='notsosleepy' data-size="medium" data-text='Testing Twitter Share' ></a>

Into tag a for twitter I'm using ng-data-url instead of data-url, but when I use this into facebook directive there is an error. There is any way to pass dynamic value to url?

Custom Icons

I am working on a project which has it's own custom icons for social sharing. But most of your code is about pulling iframes. you should add feature for custom icons.

Define Image to share

Is there a way to define which image to share.
Normally it's may set with og:image - MetaTag. How can I set it with your script?

bower version

can you please update bower version of package. In bower latest available version is 0.0.7.

Share count not updated

Hello and thanks for this Directive. I succed to install it via Git (I did not use bower).

Nevertheless each time I want to share on Facebook All is properly working except that the counter of share is not incrementing ? I of course read the IMPORTANT note :

"
For Correct Sharing of links and updating share count you must enable HTML5 Mode True for your application. i.e No # in URL'S .

angular.module('testing').config(function($locationProvider){
$locationProvider.html5Mode(true).hashPrefix('!');
});
"

So if we try the plunkr demo

this is the code I have now for script.js

angular.module('testing',['djds4rce.angular-socialshare'])
.run(function($FB){
  $FB.init('386469651480295');
});

angular.module('testing').config(function($locationProvider){
         $locationProvider.html5Mode(true).hashPrefix('!');
    })

.controller('temp',function($scope){

});

Did I miss something ?

Best Regards
Phoe

Facebook share overridden

Hello,

I love your directive, it sounds really good.

However, whenever I try to use share a page on facebook, data-url, data-title ... are being ignored and the directive try to share the root url of the website.

In my page, I use some meta informations, like meta title, description, keywords ... Maybe it's interfering with the directive.

Any idea?

Thanks

Development workflow

When I first began the project I had a setup on plunkr and made a dirty little demo and that was also the development workflow.I was not sure any one would ever use this library. 2 years and 150+ stars later it is painful to continuously develop this way due to lack of a local development environment.

Please ignore this issue

Hi,

I got an error on link function of all directive : actually, the controller ctrl is passed but it does not reference the controller "controller" it's an empty shell. So when ctrl.init() is called in the link function i got on all link functions:

TypeError: undefined is not a function
    at link (http://localhost:3000/bower_components/angular-social/angular-social.src.js:341:18)

Thanks in advance

Add License

Great library. Please add a LICENSE file or an attribution in the README. Thanks!

Facebook like button

Can I add Facebook like button to existing share button?
If it's simple, would someone tell me how to implement it?
Thank you.

Social like buttons

How I can show social like buttons? is your directive support that feature?

Thanks

angular-socialshare and previous version of angular.

Hi,

I'm using AngularJS v1.2.16. I can't enable HTML5 Mode True for my application as $locationProvider is supported by a later version of angular.

I notice on the plunker example that the number of shares is being displayed:
http://plnkr.co/edit/Cah9FtwXDrUMQjChdBG2?p=preview

The plunker uses v1.2.6, I changed it to v 1.2.16 and it still worked so I assume it will still work.

Can you please confirm the number of shares still work if not the # in url?

Thank you

error in 'Getting Started' Text

Hi, you write in Getting Started on the GitHub Landing Page
<style rel='stylesheet' type='text/css' href="bower_components/angular-socialshare/angular-socialshare.min.css"></style>

but shouldn't it be
<link rel='stylesheet' href="bower_components/angular-socialshare/angular-socialshare.min.css">

?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.