Feed link doesn't work - stream

I'm using the Facebook PHP SDK to developp my app.
From this morning, when I publish an automatic post on a user's feed, everything is ok but the link doesn't work anymore... (no reaction on click)
Once the feed is published, the target of the link is "http://www.facebook.com/connect/uiserver.php?app_id=2711...site.com/annonce?a=62&response_type=code&display=page" (and doesn't work)
I replace the name of my website by mysite.com for this example
Here is my code :
$feed_message = utf8_encode("J'ai besoin de : ".$A_titre);
$feed_picture = "http://www.mysite.com/graph/icon.png";
$feed_link = "http://www.mysite.com/annonce?a=".$ins_id; // go to my website not app
$feed_linkname = utf8_encode($A_titre);
$feed_description = utf8_encode($me_firstname)." a besoin de...";
$result = $fb->api('/me/feed/','post',array('message'=>$feed_message,'picture'=>$feed_picture,'link'=>$feed_link,'name'=>$feed_linkname,'description'=>$feed_description));
Do you have any idea of what i can do to fix it ?
Thanks

I have the same problem. It seems that it's linked to the new "Enhanced Auth Dialog".
I deactivated it since the timeline is not ready anyway, and there's no more http://www.facebook.com/connect/uiserver.php?app_id= appended to the links on the user's wall.

Related

Changing CurrentAccessToken in Facebook Unity SDK

I'm trying to post to a Facebook page AS the page using the Unity Facebook SDK running on iOS. As I understand, to do that, I need the pages access token with manage_pages and publish_pages. I know that I can get it from /me/accounts?fields=access_token, but how do I tell AccessToken.CurrentAccessToken to use my pages access token instead?
Right now i'm using the following:
var wwwForm = new WWWForm();
//wwwForm.AddField ("access_token", "A-T I NEED");
wwwForm.AddBinaryData("image", screenshot, "InteractiveConsole.png");
wwwForm.AddField("message", "herp derp. I did a thing! Did I do this right?");
FB.API("/PAGE-ID/photos", HttpMethod.POST, HandleResult, wwwForm);
I tried putting the access token manually, but that didn't work (so I commented it out).
With this as it is I'm getting an error, telling me that I need publish_actions, wich is not correct since I'm not trying to post as the user. If I also get publish_actions the Post goes online, but is posted to the page as the user speaking. (User is also Admin)
Any Ideas ? Thanks!
So, I filed a bug report to facebook and as it turns out: "… at this time this functionality is not supported." Wich simply means there is now way to use the Page Access Token you acquired via the FB.API within the FB.API. And they are not going to tell you abot it in the documentation.
As a workaround I simply use a UnityWebRequest like this:
IEnumerator UploadToPage(byte[] screenshot) {
var wwwForm = new WWWForm();
wwwForm.AddField("message", "herp derp. I did a thing! Did I do this right?");
wwwForm.AddBinaryData("image", screenshot, "Test.png");
string url = "https" + "://graph.facebook.com/"+ PageID + "/photos";
url += "?access_token=" + PageAccessToken;
using (UnityWebRequest www = UnityWebRequest.Post(url, wwwForm))
{
yield return www.Send();
if (www.isError)
{
Debug.Log(www.error);
}
else
{
Debug.Log("Form upload complete!");
}
}
Debug.Log(url);
}

MVC5 - Request.Browser information - Reports wrong type for Chrome on iOS

I have an MVC 5 (C#) application. When a user hits the home page, I log the hit, along with the user's browser information. The C# code looks as follows:
if (!Request.Browser.Crawler && Request.UserHostAddress != "::1")
{
Entities.SiteActivity siteActivity = new SiteActivity()
{
Address = Request.UserHostAddress,
BrowserMajorVersion = Request.Browser.MajorVersion.ToString(),
BrowserMinorVersion = Request.Browser.MinorVersion.ToString(),
BrowserName = Request.Browser.Browser,
BrowserPlatform = Request.Browser.Platform,
BrowserType = Request.Browser.Type,
Page = "Home",
Url = Request.Url.ToString()
};
this.SiteActivityData.Save(siteActivity);
When I hit the page from my iPad using Chrome, the browser name and type is 'Safari', and the Platform registers as Unknown. I'm curious why the Chrome browser on iOS is sending information that it's Safari, and why the platform doesn't show as iOS? Is there a better way to do what I'm doing?
51Degrees.Mobi offers advanced device detection. It may help you.
This blog from Steve Sanderson is very useful too.
http://blog.stevensanderson.com/2010/12/17/using-51degreesmobi-foundation-for-accurate-mobile-browser-detection-on-aspnet-mvc-3/

Building Twitter profile image url with Twitter user id

Is there any way of building a profile image url with user id or screen name? I store user ids in database but i don't want to store profile image url.
edit:
I don't want to make a api call too. I want to put user_id inside a url like
<img src="https://twitter.com/users/profile_pic?user_id=123"> Is there a url to do this?
With API 1.1 you can achieve this using these URLs:
https://twitter.com/[screen_name]/profile_image?size=mini
https://twitter.com/[screen_name]/profile_image?size=normal
https://twitter.com/[screen_name]/profile_image?size=bigger
https://twitter.com/[screen_name]/profile_image?size=original
Official twitter documentation Profile Images and Banners
Example
https://twitter.com/TwitterEng/profile_image?size=original
will redirect to
https://pbs.twimg.com/profile_images/875168599299637248/84CkAq6s.jpg
As of June 2020, both the accepted answer and avatars.io no longer work. Here are two alternatives:
unavatar.io
(formerly unavatar.now.sh)
Unavatar can get pictures from quite a few different places including Twitter. Replace [screen_name] in the URL below with the Twitter username you want.
<img src="https://unavatar.io/twitter/[screen_name]" />
For example:
<img src="https://unavatar.io/twitter/jack" width="100" height"100" />
If the demo above ever stops working, it's probably because unavatar.io is no longer available.
Unavatar is open source though, so if it does go down, you can deploy it yourself from the GitHub repo — it even has "Deploy to Vercel/Heroku" buttons. The code to fetch Twitter avatars specifically is here, so you could also use that as part of your own backend.
twivatar.glitch.me
⚠️ As of July 2021 this option no longer works, see the one above instead!
If you want an alternative, you can also use twivatar.glitch.me. Replace [screen_name] in the URL below with the Twitter username you want.
<img src="https://twivatar.glitch.me/[screen_name]" />
For example:
<img src="https://twivatar.glitch.me/jack" width="100" height"100" />
If the demo above ever stops working, it's probably because twivatar.glitch.me is no longer available.
By the way, I didn't build either of these services, they were both made by other people.
Introducing the easiest way to get a Twitter Profile Image without using the Twitter API:
Using http://avatars.io/
As #AlexB, #jfred says, it doesn't work at all on mobile devices.
And it's quite a hard way to get a redirected URL using common frameworks like PHP or JavaScript in your single page.
Simply call http://avatars.io/twitter/ruucm at your image tag, like
<img src="https://avatars.io/twitter/ruucm" alt="twt_profile" border="0" width="259"/>
I've tested it with Angular 2+ and it works without any problem.
As of February 20, 2020 it would appear this is impossible. Using the API seems like the only option at the moment. For more info see my question I've opened here: Twitter profile picture images now blocked on most domains
Based on the answer by #Cristiana214
The following PHP snippet can be used to make the https://twitter.com/[screen_name]/profile_image?size=normal trick work on mobile.
Due to twitters redirect to the mobile version of the site links such as https://twitter.com/[screen_name]/profile_image?size=normal get broken on mobile devices
So the script gets the redirect response (to the user avatar) extracts the address then redirects the page itself
if (!isset($_GET['id'])) $_GET['id'] = 'twitter';
$urlget = curl_init();
curl_setopt($urlget, CURLOPT_URL, 'https://twitter.com/' . $_GET['id'] . '/profile_image?size=normal');
curl_setopt($urlget, CURLOPT_HEADER, true);
curl_setopt($urlget, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($urlget);
preg_match_all("/location: (.*)/", $res, $found);
header('Location: ' . $found[1][0]);
So this could be accesses as twitteravatar.php?id=twitter which (at time of writing) reloads to https://pbs.twimg.com/profile_images/767879603977191425/29zfZY6I_normal.jpg
Not pretty but works.
You can get it using the users/show method of the Twitter API -- it does exactly what you described. You give it a the ID or the screen name, and it returns a bunch of data, including profile_image_url.
I found such a solution with C#:
public string Text_toTextFinder(string text, string Fromhere, string Here)
{
int start = text.IndexOf(Fromhere) + Fromhere.Length;
int finish = text.IndexOf(Here, start);
return text.Substring(start, finish - start);
}
string getPhotoURL(string UserName, string size ="x96")
{
using (WebClient client = new WebClient())
{
client.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
string htmlCode = client.DownloadString("https://twitter.com/" + UserName);
return Text_toTextFinder(Text_toTextFinder(htmlCode, "<td class=\"avatar\">", "</td>"), "src=\"", "\"").Replace("normal",size);
}
}
For use:
MessageBox.Show(getPhotoURL("screen_name")); //size = 96x96
MessageBox.Show(getPhotoURL("screen_name","normal"));
MessageBox.Show(getPhotoURL("screen_name","200x200"));
MessageBox.Show(getPhotoURL("screen_name","400x400"));
There is no way to do that. In fact Twitter doesn't provide a url to do that like facebook does ( https://graph.facebook.com//?fields=picture)
The issue is report but the status is: 'WontFix', take a look:
https://code.google.com/p/twitter-api/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Stars%20Type%20Bug%20Status%20Summary%20Opened%20Modified%20Component&groupby=&sort=&id=242#makechanges
Well I'm using a tricky way via PHP Dom Parser
include('simple_html_dom.php');
$html = file_get_html('http://twitter.com/mnckry');
$img = array();
foreach($html->find('img.size73') as $e)
$img[] = $e->src;
foreach($html->find('.profile-header-inner') as $e)
$img[] = str_replace("')", "", str_replace("url('", "", $e->{'data-background-image'}));
echo $img[0];//Avatar
echo "<br>";
echo end($img);//ProfileBG
This will give you something like this;
https://pbs.twimg.com/profile_images/378800000487958092/e04a191de329fcf8d000ca03073ad594_bigger.png
to get 2 other size; for big version remove, "_bigger" for smaller version replace "_bigger" with "_normal"
With version 1.1, use
http://a0.twimg.com/profile_images/XXXXX/afpecvf41m8f0juql78p_normal.png
where XXXXX is the User Id

Create Snapshot/Thumbnail of a blog entry using mvc

I need to generate a snapshot from multiple links of blogs.
What i have is a list of text like these
"Report: Twitter Will Release Music Discovery App This Month http://on.mash.to/10L1v49 via #mashable"
I want to show the links as snapshot of the blog, followed by its text in my view. Or at least i need to get the picture attached to the blog.
Using facebook debug, http://developers.facebook.com/tools/debug ,i am getting this..
fb:app_id: 122071082108
og:url: http://mashable.com/2013/03/13/twitter-music-app/
og:type: article
og:title: Report: Twitter Will Release Music Discovery App This Month
og:image:
og:description: Twitter is planning to release a standalone music app for iOS called Twitter Music as soon as the end of this month, according to CNET. CNET reports that Twitter Music will help...
og:site_name: Mashable
og:updated_time: 1363267654
I tried the same link from my c# code, accessed the link with parameter 'q' as my desired link. I got the same html as reply but i am unable to find the image associated as it is coming differently for different links.
Can anyone suggest a better method to do this in mvc?
My code in controller to access facebook debug :
var client = new RestClient
{
BaseUrl = "http://developers.facebook.com/tools/debug/og/object"
};
var request = new RestRequest
{
DateFormat = DataFormat.Xml.ToString(),
Resource = "Add",
Method = Method.GET
};
request.AddParameter("q", "http://on.mash.to/10L1v49");
IRestResponse response = client.Execute(request);
var content = response.Content; // raw content as string
What i understand from your question is, you need something like the preview of a link what we get on pasting some link on facebook share area.
Facebook debug method returns an html page which has the image of your blog entry from the link given.
Use HtmlAgilityPack to parse your html returned from facebook debug
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(content);
HtmlNode root = doc.DocumentNode;
var imageurl = doc.DocumentNode.SelectNodes("//img/#src").LastOrDefault();
string imagesrc = imageurl.OuterHtml.ToString();
int start = imagesrc.IndexOf("url=");
int to = imagesrc.IndexOf("\"", start + "url=".Length);
string s = imagesrc.Substring(
start + "url=".Length,
to - start - "url=".Length);
string a = Uri.UnescapeDataString(s);
and..there you have your image of the blog entry. Same function can be modified to retireve the title, description and the updated time of the blog entry.

Trying to detect a call to my web app made by facebook

In my asp.net MVC app, I'm trying to know if this is facebook who is calling one of my urls (when a link to my site is shared as a FB status and FB tries to get some meta tags for opengraph). I have tried URlReferrer, which is empty, and UserHostName which shows an IP addr.
You could do as Tejs suggests, something like:
IPHostEntry IpEntry = Dns.GetHostByAddress(HttpContext.Current.Request.UserHostAddress);
//OR
IPHostEntry IpEntry = Dns.GetHostByAddress(HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]);
if(IpEntry.HostName.Contains("facebook.com"))
{
//Coming from facebook.com
}
Seems like this can be done like so:
if ((!string.IsNullOrWhiteSpace(HttpContext.Request.UserAgent) && HttpContext.Request.UserAgent.ToLower().Contains("facebookexternalhit")) ||
((HttpContext.Request.UrlReferrer != null) && HttpContext.Request.UrlReferrer.Host.ToLower().Contains("facebook.com")))
This way I know if Facebook is grabbing opengraph data or if someone clicks the shared link from a facebook page.

Resources