Facebook & Classic ASP - Passing custom parameters to fan page tab - error with no data - facebook

We have our app working using this code (Is it possibile to pass parameters to the callback URL of a FB app which is accessed through a tab?), but the issue arises when there is no app_data parameter passed in. Here is an example of what we mean:
Works Fine: ("test" is written out fine)
https://www.facebook.com/phillypours/app_397493550309543?app_data=test
Does NOT Work:
https://www.facebook.com/phillypours/app_397493550309543
Code used with Base64 Encode & JSON Decode:
myArray = Split(Request("signed_request"), ".")
encoded_sig = myArray(0)
payload = myArray(1)
sig = base64_decode(Replace(encoded_sig, "-_", "+/"))
set data = JSON.parse(base64_decode(Replace(payload, "-_", "+/")))
Response.Write data.app_data
This is the error we receive when no parameter is passed in:
Object doesn't support this property or method: 'data.app_data'
Anyone have any thoughts on how to trap for this? I cannot do anything with "data.app_data" since this is what throws the error.
Any help would be greatly appreciated!!!
Thank you.
Dennis

I found a work around for this. Wanted to share to others could benefit. thanks, Dennis
<!--#INCLUDE VIRTUAL="/includes/fb_base64.asp"-->
<!--#INCLUDE VIRTUAL="/includes/fb_json_decode.asp"-->
Function parsePageSignedRequest()
If Request("signed_request") <> "" Then
myArray = Split(Request("signed_request"), ".")
payload = myArray(1)
payload_decoded = base64_decode(payload)
set data = JSON.parse(payload_decoded)
If instr(payload_decoded,"""app_data""") Then
AppData = data.app_data
End If
If instr(payload_decoded,"liked"":true,") Then
LikeStatus = True
End If
End If
End Function

Related

urlread2 not working with marketwatch

I have been using urlread2 to read financial statements from marketwatch, and it was previously working. I am trying to run the same Matlab script I previously ran and cannot get it work. The html variable returned is an empty matrix.
Any ideas ?
Here is a link to the function: https://se.mathworks.com/matlabcentral/fileexchange/35693-urlread2
I know the function works, as I tried it running it on a different website.
Here is the Matlab script I am using.
url = ['http://www.marketwatch.com/investing/stock/AAPL/financials/'];
url = strrep(url,' ','');
query = 'urlread2';
params = {'term' query};
queryString = http_paramsToString(params,1);
url = [url '?' queryString];
[html,extras] = urlread2(url);

Django send welcome email after User created using signals

I have a create_user_profile signal and I'd like to use same signal to send a welcome email to the user.
This is what I wrote so far in my signals.py:
#receiver(post_save, sender=User)
def update_user_profile(sender, instance, created, **kwargs):
if created:
UserProfile.objects.create(user=instance)
instance.profile.save()
subject = 'Welcome to MyApp!'
from_email = 'no-reply#myapp.com'
to = instance.email
plaintext = get_template('email/welcome.txt')
html = get_template('email/welcome.html')
d = Context({'username': instance.username})
text_content = plaintext.render(d)
html_content = html.render(d)
try:
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
msg.attach_alternative(html_content, "text/html")
msg.send()
except BadHeaderError:
return HttpResponse('Invalid header found.')
This is failing with this error:
TypeError at /signup/
context must be a dict rather than Context.
pointing to the forms.save in my views.py file.
Can you help me to understand what's wrong here?
Just pass a dict to the render instead of a Context object
d = {'username': instance.username}
text_content = plaintext.render(d)
On django 1.11 the template context must be a dict:
https://docs.djangoproject.com/en/1.11/topics/templates/#django.template.backends.base.Template.render
Try to just remove the Context object creationg.
d = {'username': instance.username}

Typoscript: how do I add a parameter to all links in the RTE?

I want to add a parameter to all links entered in the RTE by the user.
My initial idea was to do this:
lib.parseFunc_RTE.tags.link {
typolink.parameter.append = TEXT
typolink.parameter.append.value = ?flavor=lemon
}
So for example:
http://domain.com/mypage.php
becomes
http://domain.com/mypage.php?flavor=lemon
which sounds great -- as long as the link does not already have a query string!
In that case, I obviously end up with two question marks in the URL
So for example:
http://domain.com/prefs.php?id=1234&unit=moon&qty=300
becomes
http://domain.com/prefs.php?id=1234&unit=moon&qty=300?flavor=lemon
Is there any way to add my parameter with the correct syntax, depending on whether the URL already has a query string or not? Thanks!
That would be the solution:
lib.parseFunc_RTE.tags.link {
typolink.additionalParams = &flavor=lemon
}
Note that it has to start with an &, typo3 then generates a valid link. The parameter in the link also will be parsed with realURL if configured accordingly.
Edit: The above solution only works for internal links as described in the documentation https://docs.typo3.org/typo3cms/TyposcriptReference/Functions/Typolink/Index.html
The only solution that works for all links that I see is to use a userFunc
lib.parseFunc_RTE.tags.link {
typolink.userFunc = user_addAdditionalParams
}
Then you need to create a php script and include in your TS with:
includeLibs.rteScript = path/to/yourScript.php
Keep in mind that includeLibs is outdated, so if you are using TYPO3 8.x (and probably 7.3+) you will need to create a custom extension with just a few files
<?php
function user_addAdditionalParams($finalTagParts) {
// modify the url in $finalTagParts['url']
// $finalTagParts['TYPE'] is an indication of link-kind: mailto, url, file, page, you can use it to check if you need to append the new params
switch ($finalTagParts['TYPE']) {
case 'url':
case 'file':
$parts = explode('#', $finalTagParts['url']);
$finalTagParts['url'] = $parts[0]
. (strpos($parts[0], '?') === false ? '?' : '&')
. 'newParam=test&newParam=test2'
. ($parts[1] ? '#' . $parts[1] : '');
break;
}
return '<a href="' . $finalTagParts['url'] . '"' .
$finalTagParts['targetParams'] .
$finalTagParts['aTagParams'] . '>'
}
PS: i have not tested the actual php code, so it can have some errors. If you have troubles, try debugging the $finalTagParts variable
Test whether the "?" character is already in the URL and append either "?" or "&", then append your key-value pair. There's a CASE object available in the TypoScript Reference, with an example you can modify for your purpose.
For anyone interested, here's a solution that worked for me using the replacement function of Typoscript. Hope this helps.
lib.parseFunc_RTE.tags.link {
# Start by "replacing" the whole URL by itself + our string
# For example: http://domain.com/?id=100 becomes http://domain.com/?id=100?flavor=lemon
# For example: http://domain.com/index.html becomes http://domain.com/index.html?flavor=lemon
typolink.parameter.stdWrap.replacement.10 {
#this matches the whole URL
search = #^(.*)$#i
# this replaces it with itself (${1}) + our string
replace =${1}?flavor=lemon
# in this case we want to use regular expressions
useRegExp = 1
}
# After the first replacement is done, we simply replace
# the first '?' by '?' and all others by '&'
# the use of Option Split allow this
typolink.parameter.stdWrap.replacement.20 {
search = ?
replace = ? || & || &
useOptionSplitReplace = 1
}
}

Parse a responseText to HTML in VBScript

I'm trying to retrieve HTML Class Names from a string variable created by responseText. I need to accomplish this using VBscript. Here is a sample of current code:
set http = createobject("Microsoft.XmlHttp")
http.open "GET","http://www.xxxxxxxxxxx.com/xxx-xxx?xxxxNumber=xxxxx",false
http.send ""
dim html : set html = CreateObject("HTMLFILE")
html.write http.responseText
dim trackdate : trackdate = html.getElementByClassName("tracking-history-date").[0].value
wscript.echo trackdate
I'm receiving the following error: Object doesn't support this property or mehtod: 'getElementByClassName'
I've run into this before. Although documented, the getElementsByClassName() method doesn't seem to actually be supported. Use something like this to work around the issue:
For Each el In html.getElementsByTagName("...")
If el.ClassName = "tracking-history-date" Then
Set trackdate = el
Exit For
End If
Next

Uploading to cloud storage with API, RequestException

Can anyone tell me why this code gets a request exception?
Google.Apis.Storage.v1.Data.Object obj = new Google.Apis.Storage.v1.Data.Object();
obj.Bucket = "testbucket1817";
obj.ContentType = "binary/octet-stream";
obj.SelfLink = #"C:\Users\User\Desktop\file";
obj.Name = "filename";
Google.Apis.Storage.v1.ObjectsResource.InsertRequest uploadrequest = new ObjectsResource.InsertRequest(storagecredentials, obj, "testbucket1817");
uploadrequest.Execute();
When run I get this error message-
Required [400]
Errors [
Message[Required] Location[ - ] Reason[required] Domain[global]
Message[Required] Location[ - ] Reason[required] Domain[global]
]
I'm not sure about the selflink thing or the content type (for an xml file) but there's nothing anywhere that actually says how this should be done.
Thanks anyone
InsertMediaUpload seems to work fine. Don't know what the difference is from InsertRequest other than I can figure out where to put the data with InsertMediaUpload. So whatever file you want to upload, just set a stream as File.Open(yourfile, FileMode.Open) and set an object like I did in the question.
Google.Apis.Storage.v1.ObjectsResource.InsertMediaUpload uploadmedia = new
ObjectsResource.InsertMediaUpload(ss, object, "bucketname", fileStream, "binary/octet-stream");
that sets up the upload and then uploadmedia.Upload() executes.
Thanks everyone!
Ross